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();
}
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;
}
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();
}
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;
}
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"));
}
Aggregations