use of net.sf.json.JsonConfig in project topcom-cloud by 545314690.
the class JsonUtil method getNoNullConfig.
public static JsonConfig getNoNullConfig() {
JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter() {
@Override
public boolean apply(Object o, String s, Object o1) {
return o1 == null || o1.equals(JSONNull.getInstance());
}
});
return config;
}
use of net.sf.json.JsonConfig in project jaffa-framework by jaffa-projects.
the class ExcelExportService method createJsonConfig.
/**
* Creates a JsonConfig with the rootClass set to the input. Adds
* custom-support for handling FlexCriteriaBean.
*/
private static JsonConfig createJsonConfig(Class rootClass) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setRootClass(rootClass);
jsonConfig.setNewBeanInstanceStrategy(new NewBeanInstanceStrategy() {
public Object newInstance(Class target, JSONObject source) throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, InvocationTargetException {
if (target == FlexCriteriaBean.class) {
try {
// Determine the name of the associated dynaClass and
// use that to instantiate the FlexCriteriaBean
JSONObject dynaClassObject = source.getJSONObject("dynaClass");
String dynaClassName = dynaClassObject.getString("name");
FlexCriteriaBean bean = FlexCriteriaBean.instance(FlexClass.instance(dynaClassName));
// Add the criteria elements
source.remove("dynaClass");
for (Iterator i = source.keys(); i.hasNext(); ) {
String key = (String) i.next();
Class propType = bean.getDynaClass() != null && bean.getDynaClass().getDynaProperty(key) != null ? bean.getDynaClass().getDynaProperty(key).getType() : String.class;
propType = findCriteriaFieldClass(propType);
Object propValue = JSONObject.toBean(source.getJSONObject(key), propType);
bean.set(key, propValue);
}
source.clear();
return bean;
} catch (Exception e) {
String s = "Exception thrown while instantiating FlexCriteriaBean from " + source;
log.error(s, e);
throw new InvocationTargetException(e, s);
}
}
return target.newInstance();
}
});
return jsonConfig;
}
use of net.sf.json.JsonConfig in project jaffa-framework by jaffa-projects.
the class ExcelExportService method createJsonConfig.
/**
* Creates a JsonConfig with the rootClass set to the input. Adds
* custom-support for handling FlexCriteriaBean.
*/
private static JsonConfig createJsonConfig(Class rootClass) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setRootClass(rootClass);
jsonConfig.setNewBeanInstanceStrategy(new NewBeanInstanceStrategy() {
public Object newInstance(Class target, JSONObject source) throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, InvocationTargetException {
if (target == FlexCriteriaBean.class) {
try {
// Determine the name of the associated dynaClass and
// use that to instantiate the FlexCriteriaBean
JSONObject dynaClassObject = source.getJSONObject("dynaClass");
String dynaClassName = dynaClassObject.getString("name");
FlexCriteriaBean bean = FlexCriteriaBean.instance(FlexClass.instance(dynaClassName));
// Add the criteria elements
source.remove("dynaClass");
for (Iterator i = source.keys(); i.hasNext(); ) {
String key = (String) i.next();
Class propType = bean.getDynaClass() != null && bean.getDynaClass().getDynaProperty(key) != null ? bean.getDynaClass().getDynaProperty(key).getType() : String.class;
propType = findCriteriaFieldClass(propType);
Object propValue = JSONObject.toBean(source.getJSONObject(key), propType);
bean.set(key, propValue);
}
source.clear();
return bean;
} catch (Exception e) {
String s = "Exception thrown while instantiating FlexCriteriaBean from " + source;
log.error(s, e);
throw new InvocationTargetException(e, s);
}
}
return target.newInstance();
}
});
return jsonConfig;
}
use of net.sf.json.JsonConfig in project jaffa-framework by jaffa-projects.
the class JaffaComponentHelper method validateJSONObject.
/**
* Validates the JSONObject class name.
*
* @param className <code>String</code> the class name.
* @param value <code>String</code> the request parameter value.
* @param error <code>String</code> the error message.
* @throws <code>InvalidParameterException</code> the exception, designed
* for use by the JCA/JCE engine classes, is thrown when an invalid
* parameter is passed to a method.
*/
private void validateJSONObject(final String className, final String value, final String error) throws InvalidParameterException {
try {
final Class<?> clazz = Class.forName(className);
clazz.newInstance();
try {
final JSONObject json = JSONObject.fromObject(value);
final JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setRootClass(clazz);
JSONSerializer.toJava(json, jsonConfig);
} catch (Exception e) {
throw new InvalidParameterException(error);
}
} catch (ClassNotFoundException e) {
throw new InvalidParameterException(error);
} catch (InstantiationException e1) {
throw new InvalidParameterException(error);
} catch (IllegalAccessException e1) {
throw new InvalidParameterException(error);
}
}
use of net.sf.json.JsonConfig in project ngtesting-platform by aaronchen2k.
the class JsonUtils method configJson.
/**
* json 配置属性,并转化时间格式
*
* @param datePattern 时间格式
* @return 返回JsonConfig
*/
public static JsonConfig configJson(String datePattern) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(datePattern));
return jsonConfig;
}
Aggregations