Posted on 2013-07-16 16:44 
张力 阅读(589) 
评论(0)  编辑  收藏  
			
			
		 
		如题,JSON在转换的时候如果你的类型是BigDecimal类型的,DAO层查找出来的数据是为null,经过JSON一转换之后就变成了0
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的源码