Search in sources :

Example 16 with JsonConfig

use of net.sf.json.JsonConfig in project Java by Everything1sPossible.

the class jsonUtil method pageToJson.

/**
 * ����ҳʵ������ת��json,�ɹ����ֶ�
 * @param result:��ҳʵ������
 * @param filterFields:��Ҫ���˵�����
 * @param dateFormat:���ڸ�ʽ��
 * @return
 */
public static <T> String pageToJson(PageResult<T> result, String[] filterFields, String dateFormat) {
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    jsonMap.put("dataList", result.getDataList());
    jsonMap.put("pageNo", result.getPageNo());
    jsonMap.put("pageSize", result.getPageSize());
    jsonMap.put("total", result.getTotal());
    jsonMap.put("pages", result.getPages());
    JsonConfig config = new JsonConfig();
    if (filterFields != null) {
        config.setExcludes(filterFields);
    }
    // 1 �������ڸ�ʽ
    if (dateFormat == null || dateFormat.equals("")) {
        // Ĭ��Ϊ������
        dateFormat = "yyyy-MM-dd";
    }
    if (dateFormat != null) {
        config.registerJsonValueProcessor(Date.class, new JsonDateTransform(dateFormat));
    }
    return JSONObject.fromObject(jsonMap, config).toString();
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONObject(net.sf.json.JSONObject)

Example 17 with JsonConfig

use of net.sf.json.JsonConfig in project ngtesting-platform by aaronchen2k.

the class JsonUtils method configJson.

/**
 * json 配置属性,如果有日期类型的,将日期类型格式成字符串,以及排除相关属性
 *
 * @param excludes    排除相关属性
 * @param datePattern 时间格式
 * @return 返回JsonConfig
 */
public static JsonConfig configJson(String[] excludes, String datePattern) {
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setExcludes(excludes);
    jsonConfig.setIgnoreDefaultExcludes(true);
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(datePattern));
    return jsonConfig;
}
Also used : JsonConfig(net.sf.json.JsonConfig)

Example 18 with JsonConfig

use of net.sf.json.JsonConfig in project ngtesting-platform by aaronchen2k.

the class JsonUtils method getJsonString4JavaPOJO.

/**
 * java对象转成json字符串
 *
 * @param javaObj    对象
 * @param dataFormat 时间格式
 * @return 返回字符串
 */
public static String getJsonString4JavaPOJO(Object javaObj, String dataFormat) {
    JsonConfig jsonConfig = configJson(dataFormat);
    JSONObject json = JSONObject.fromObject(javaObj, jsonConfig);
    return json.toString();
}
Also used : JSONObject(net.sf.json.JSONObject) JsonConfig(net.sf.json.JsonConfig)

Example 19 with JsonConfig

use of net.sf.json.JsonConfig in project ngtesting-platform by aaronchen2k.

the class JsonUtils method configJson.

/**
 * json 配置属性,排除相关属性
 *
 * @param excludes 排除相关属性
 * @return 返回JsonConfig
 */
public static JsonConfig configJson(String[] excludes) {
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setExcludes(excludes);
    jsonConfig.setIgnoreDefaultExcludes(true);
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor("yyyy-MM-dd"));
    return jsonConfig;
}
Also used : JsonConfig(net.sf.json.JsonConfig)

Example 20 with JsonConfig

use of net.sf.json.JsonConfig in project jmeter-plugins-manager by undera.

the class PluginTest method testVersionChanges.

@Test
public void testVersionChanges() {
    String str = "{\"id\": 0,  \"markerClass\": 0, \"name\": 0, \"description\": 0, \"helpUrl\": 0, \"vendor\": 0, \"installerClass\": \"test\", " + "\"versions\" : { \"0.1\" : { \"changes\": \"fix verified exception\" } }}";
    Plugin p = Plugin.fromJSON(JSONObject.fromObject(str, new JsonConfig()));
    assertEquals("fix verified exception", p.getVersionChanges("0.1"));
    str = "{\"id\": 0,  \"markerClass\": 0, \"name\": 0, \"description\": 0, \"helpUrl\": 0, \"vendor\": 0, \"installerClass\": \"test\", " + "\"versions\" : { \"0.1\" : {  } }}";
    p = Plugin.fromJSON(JSONObject.fromObject(str, new JsonConfig()));
    assertNull(p.getVersionChanges("0.1"));
}
Also used : JsonConfig(net.sf.json.JsonConfig) Test(org.junit.Test)

Aggregations

JsonConfig (net.sf.json.JsonConfig)28 JSONObject (net.sf.json.JSONObject)17 File (java.io.File)10 HashMap (java.util.HashMap)10 JSONArray (net.sf.json.JSONArray)10 Test (org.junit.Test)10 URL (java.net.URL)7 PrintWriter (java.io.PrintWriter)5 JSON (net.sf.json.JSON)5 Writer (java.io.Writer)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 NewBeanInstanceStrategy (net.sf.json.util.NewBeanInstanceStrategy)2 FlexClass (org.jaffa.flexfields.FlexClass)2 FlexCriteriaBean (org.jaffa.flexfields.FlexCriteriaBean)2 Status (io.milton.http.Response.Status)1 NameAndError (io.milton.http.webdav.PropFindResponse.NameAndError)1 CollectionResource (io.milton.resource.CollectionResource)1