如題,JSON在轉換的時候如果你的類型是BigDecimal類型的,DAO層查找出來的數據是為null,經過JSON一轉換之后就變成了0
JSON的JSONObject類的 private static void setValue( JSONObject jsonObject, String key, Object value, Class type,
JSON的JSONObject類的 private static void setValue( JSONObject jsonObject, String key, Object value, Class type,
JsonConfig jsonConfig, boolean bypass ) 這個方法里面的 if( value == null ){
value = jsonConfig.findDefaultValueProcessor( type )
.getDefaultValue( type );這個方法處理默認值
最終會有一個類處理所有的無值的默認值
最終會有一個類處理所有的無值的默認值
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();
}
}
所以有同樣問題的時候可以試著修改JSON的源碼
所以有同樣問題的時候可以試著修改JSON的源碼