如果未设置的话默认是DefaultDefaultValueProcessor
public class DefaultDefaultValueProcessor implements DefaultValueProcessor {
public Object getDefaultValue( Class type ) {
if( JSONUtils.isArray( type ) ){
return new JSONArray();
}else if( JSONUtils.isNumber( type ) ){
if( JSONUtils.isDouble( type ) ){
return new Double( 0 );
}else{
return new Integer( 0 );
}
}else if( JSONUtils.isBoolean( type ) ){
return Boolean.FALSE;
}else if( JSONUtils.isString( type ) ){
return "";
}
return JSONNull.getInstance();
}
}
在jsonConfig 注册defaultValueProcessor
// 设置Integer类型为空的默认值 json-lib默认是0
jsonConfig.registerDefaultValueProcessor(Integer.class,
new DefaultValueProcessor() {
public Object getDefaultValue(Class type) {
return null;
}
});
这样转换时Integer类型如果为null转换还是null,不会被转为0
分享到:
相关推荐
JSONObject对象依赖的6个jar包,非常重要日包,可以解析Response响应日JSON JSONObject json = JSONObject.fromObject(Response);
Java开发所需要的jar,全部在包里。JSONObject jsonObject = JSONObject.fromObject(Map);
JSONObject相关依赖架包,包含1、com.alibaba.fastjson.JSONArray依赖jar 2、net.sf.json.JSONObject依赖jar
com.alibaba.fastjson.JSONObject(JAR包) JSONObject(JAR包)
JSONObject jsonobj=JSONObject.fromObject(resultData);//将字符串转化成json对象 JSONArray jsonArray = jsonobj.getJSONArray("data");//获取数组 List< PubUnit> pubUnits = new ArrayList(); for (int i = ...
net.sf.json.JSONObject相关依赖架包,导入项目后,JSONObject.fromObject()方法就可以使用了
包含以下java源文件: ...com.google.gson.JsonNull.class com.google.gson.JsonObject.class com.google.gson.JsonParseException.class com.google.gson.JsonParser.class com.google.gson.JsonPrimitive.class ...
在web中的jsonobject有个直接可以tobean的方法用起来非常方便,可android没有,所以通过反射机制学习web中的jsonobject写了一个jsonobject的tobean,方便使用.
JsonObject转换Date日期的时候出现问题解决date封装成json数据出现的问题
通过JSONObject json = JSONObject.fromObject(student);将构造好的Student对象转换为JSON对象,Student如上文所述。 进入此方法后会继续调用fromObject(Object, JsonConfig)的重载方法,在此重载方法中会通过...
NULL 博文链接:https://bijian1013.iteye.com/blog/2310861
JSONObject对象相关的jar包依赖,一共有6个;还有maven环境下管理的jar包
JSONObject需要的6个 jar包(commons-beanutils-1.7.0.jar,commons-collections-3.1.jar,commons-lang-2.5.jar,commons-logging.jar,ezmorph-1.0.3.jar,json-lib-2.1-jdk15.jar)
JSONObject jsonObject =JSONObject.fromObject(new JsonBean()); 4. 数组转换成json代码 boolean[] boolArray = newboolean[] { true, false, true }; JSONArray jsonArray1 =JSONArray.fromObject(boolArray); ...
在web项目中经常会用到json数据(如:struts2处理请求返回json数据给jsp解析),因此,JSONObject对象是必备的,这时就需要引入相关的jar包了。
JSONObject jodata =JSONObject.fromObject(temp); JSONObject joa =JSONObject.fromObject(jodata.get("data").toString()); JSONArray ja=JSONArray.fromObject(joa.get("a")); for(int i=0;i<ja.size();i++){ ...
net.sf.json.JSONObject相关jar包
JSONObject jsonObject = JSONObject.fromObject(json); JSONObject resultJSON = JSONObject.fromObject(jsonObject); Map map = (Map)JSONObject.toBean(resultJSON, Map.class); Iterator it...
org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包
用于Json转换的Json-object,newtonsoft_&_jsonObject.zip