Package net.sf.json

Examples of net.sf.json.JsonConfig


import org.jrest4guice.rest.commons.json.annotations.JsonExclude;

public class JsonConfigFactory {
  public static JsonConfig createJsonConfig(Object bean) {
    JsonConfig jsonConfig = new JsonConfig();
    if(bean == null)
      return jsonConfig;
    if (bean instanceof List) {
      try {
        bean = ((List<?>) bean).get(0);
View Full Code Here


    return new XMLSerializer().write(JSONObject.fromObject(this,
        JsonConfigFactory.createJsonConfig(this.content)));
  }

  public String toJson() {
    JsonConfig jsonConfig = JsonConfigFactory.createJsonConfig(this.content);
   
    jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor());
    jsonConfig.registerJsonValueProcessor(Timestamp.class,new DateJsonValueProcessor())

    JsonConfigFactory.filteExcludes(this, jsonConfig);
    return JSONObject.fromObject(this,
        jsonConfig).toString();
  }
View Full Code Here

    }

    protected JSONOutPutConfig config = new JSONOutPutConfig();

    public JSON _toJson(Object obj) {
        JsonConfig config = new JsonConfig();
        config.setIgnoreDefaultExcludes(false);
        config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor());
        if (obj instanceof Collection) {
            return JSONArray.fromObject(obj, config);
        }
        return JSONObject.fromObject(obj, config);
    }
View Full Code Here

  public synchronized EventRunner send(JSONPacket command) throws JSONException,IOException{
    logger.info("Sending: "+command.getClass().getSimpleName()+": "+command);
    String response = put(command.toString());
    logger.info("Received: "+response.trim()+" after "+command.getClass().getSimpleName());
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setExcludes(new String[]{"cookie", "length"});
    final JSONArray jsonResponse = (JSONArray) JSONSerializer.toJSON(response,jsonConfig);
    return signalEvents(jsonResponse);
  }
View Full Code Here

  private EventRunner signalEvents(JSONArray jsonResponse) throws JSONException{
    final JSONPacket[] events = new JSONPacket[jsonResponse.size()];
    for(int i=0; i<jsonResponse.size();i++){
      JSONObject jsonEvent = jsonResponse.getJSONObject(i);
      JsonConfig jsonConfig = new JsonConfig();
      jsonConfig.setRootClass( eventTypes.get(jsonEvent.get("type")) );
      try {
        events[i]=(JSONPacket) JSONObject.toBean( jsonEvent, jsonConfig );
      } catch (ClassCastException e) {
        throw new IllegalStateException("Couldn't unmarshall: "+jsonEvent,e);
      }
View Full Code Here

    writer.close();
  }

  protected void writeMap(Map<?, ?> map) throws IOException
  {
    JsonConfig config = new JsonConfig();
    config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    String json = JSONObject.fromObject(map, config).toString();
    writeInResponse(json);
  }
View Full Code Here

            sb.append(buffer, 0, len);
        }
        if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {
            JSONArray jsonArray = JSONArray.fromObject(sb.toString());
            if (target.getClass().isArray()) {
                JSONArray.toArray(jsonArray, target, new JsonConfig());
            } else {
                JSONArray.toList(jsonArray, target, new JsonConfig());
            }

        } else {
            JSONObject jsonObject = JSONObject.fromObject(sb.toString());
            JSONObject.toBean(jsonObject, target, new JsonConfig());
        }
    }
View Full Code Here

            sb.append(buffer, 0, len);
        }
        if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {
            JSONArray jsonArray = JSONArray.fromObject(sb.toString());
            if (target.getClass().isArray()) {
                JSONArray.toArray(jsonArray, target, new JsonConfig());
            } else {
                JSONArray.toList(jsonArray, target, new JsonConfig());
            }

        } else {
            JSONObject jsonObject = JSONObject.fromObject(sb.toString());
            JSONObject.toBean(jsonObject, target, new JsonConfig());
        }
    }
View Full Code Here

        helper = new Helper();
    }

    public void sendContent(PropFindableResource wrappedResource, String encodedUrl, OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException {
        log.debug("sendContent: " + encodedUrl);
        JsonConfig cfg = new JsonConfig();
        cfg.setIgnoreTransientFields(true);
        cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);

        JSON json;
        Writer writer = new PrintWriter(out);
        String[] arr;
        if (propertyBuilder == null) {
View Full Code Here

        this.patchHandler = patchHandler;
    }

    public void sendContent( OutputStream out, Range range, Map<String, String> params, String contentType ) throws IOException, NotAuthorizedException {
        log.debug( "sendContent");
        JsonConfig cfg = new JsonConfig();
        cfg.setIgnoreTransientFields( true );
        cfg.setCycleDetectionStrategy( CycleDetectionStrategy.LENIENT );

        List<FieldError> errors = new ArrayList<FieldError>();
        if( resp != null && resp.getErrorProperties() != null ) {
            log.debug( "error props: " + resp.getErrorProperties().size());
            for( Status stat : resp.getErrorProperties().keySet() ) {
View Full Code Here

TOP

Related Classes of net.sf.json.JsonConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.