Package net.sf.json

Examples of net.sf.json.JsonConfig


     *   
     * @param datePattern  
     * @return  
     */  
    public static JsonConfig configJson(String datePattern) {   
        JsonConfig jsonConfig = new JsonConfig();   
        jsonConfig.setExcludes(new String[] { "" });   
        jsonConfig.setIgnoreDefaultExcludes(false);   
        jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
        jsonConfig.registerJsonValueProcessor(Date.class,   
                new JsonDateValueProcessor(datePattern));   
  
        return jsonConfig;   
    }   
View Full Code Here


  
        return jsonConfig;   
    }   

  public static void outJson(Object obj) {
        JsonConfig jsonConfig = configJson("yyyy-MM-dd HH:mm:ss");   
    outJsonString(JSONObject.fromObject(obj,jsonConfig).toString());
  }
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

  /**
   * json-libĬ�ϲ�֧��java.sql.Date�����л���Ҫ���л��Լ����࣬ʵ��һ��BeanProcessor���� JSONObject
   * jsonObj = JSONObject.fromObject(row,JsonUtil.filterDate());
   */
  public static JsonConfig filterDate() {
    JsonConfig config = new JsonConfig();
    JsDateJsonBeanProcessor beanProcessor = new JsDateJsonBeanProcessor();
    config.registerJsonBeanProcessor(java.sql.Date.class, beanProcessor);
    return config;
  }
View Full Code Here

        filterConfig(includePropertys, exclude));
    return json;
  }

  public static JsonConfig filterDateConfig() {
    JsonConfig cfg = new JsonConfig();
    cfg.registerJsonValueProcessor(java.util.Date.class,
        new JsonValueProcessor() {
          private final String format = "yyyy-MM-dd HH:mm:ss";

          public Object processObjectValue(String key, Object value,
              JsonConfig arg2) {
View Full Code Here

   * @param propertys
   * @param exclude
   * @return
   */
  private static JsonConfig filterConfig(String[] propertys, boolean exclude) {
    JsonConfig config = new JsonConfig();
    // config.setExcludes(excludeProperty);
    NamedPropertyFilter filter = new NamedPropertyFilter(propertys);
    filter.setExclude(exclude);
    // config.setJavaPropertyFilter(filter);
    config.setJsonPropertyFilter(filter);
    return config;
  }
View Full Code Here

    config.setJsonPropertyFilter(filter);
    return config;
  }

  private static JsonConfig filterConfig() {
    JsonConfig config = new JsonConfig();
    JsonValueProcessor jp = new DateJsonValueProcessor(
        "yyyy-MM-dd HH:mm:ss");
    config.registerJsonValueProcessor(java.sql.Timestamp.class, jp);
    return config;
  }
View Full Code Here

  public static final String encodeObject2Json(Object pObject, String pFormatString) {
    String jsonString = "[]";
    if (G4Utils.isEmpty(pObject)) {
      // log.warn("传入的Java对象为空,不能将其序列化为Json资料格式.请检查!");
    } else {
      JsonConfig cfg = new JsonConfig();
      cfg.registerJsonValueProcessor(java.sql.Timestamp.class, new JsonValueProcessorImpl(pFormatString));
      cfg.registerJsonValueProcessor(java.util.Date.class, new JsonValueProcessorImpl(pFormatString));
      cfg.registerJsonValueProcessor(java.sql.Date.class, new JsonValueProcessorImpl(pFormatString));
      if (pObject instanceof ArrayList) {
        JSONArray jsonArray = JSONArray.fromObject(pObject, cfg);
        jsonString = jsonArray.toString();
      } else {
        JSONObject jsonObject = JSONObject.fromObject(pObject, cfg);
View Full Code Here

        String jsonString;

        if (data == null) {
            jsonString = "{}";
        } else {
            JsonConfig jsonConfig = new JsonConfig();
            jsonConfig.setExcludes(excludes);
            jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
            Object jsObj = JSONSerializer.toJSON(data,jsonConfig);
            jsonString = jsObj.toString();
        }

        try {
View Full Code Here

    public static String toJson(Object obj) {
        return toJson(obj,null);
    }
   
    public static String toJson(Object obj, String[] excludes) {
        JsonConfig c = new JsonConfig();
        if (excludes != null) {
            c.setExcludes(excludes);
        }
        c.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        Object jsObj = JSONSerializer.toJSON(obj, c);
       
        String result = jsObj.toString();
       
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.