json返回数据,属性值为null或空的问题

当使用com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter转换返回数据为json时,会省略掉为空为null的属性值。

解决办法在sping-mvc.xml配置json转换器时加上对空和null的处理,配置如下:

  1. <mvc:annotation-driven>  
  2.         <mvc:message-converters>  
  3.             <bean  
  4.                 class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
  5.                 <description>JSON转换器description>  
  6.                 <property name="supportedMediaTypes">  
  7.                     <list>  
  8.                         <value>application/json;charset=UTF-8value>  
  9.                         <value>text/html;charset=UTF-8value>  
  10.                     list>  
  11.                 property>  
  12.                 <property name="features">  
  13.                     <array>  
  14.                         <value>QuoteFieldNamesvalue>  
  15.                         <value>WriteDateUseDateFormatvalue>  
  16.                           
  17.                         <value>WriteNullListAsEmptyvalue>  
  18.                           
  19.                         <value>WriteNullStringAsEmptyvalue>  
  20.                           
  21.                         <value>WriteNullBooleanAsFalsevalue>  
  22.                     array>  
  23.                 property>  
  24.             bean>  
  25.         mvc:message-converters>  
  26. mvc:annotation-driven>

网上大神是这样解释,豁然开朗。

我这边是这样配置的:


	
	    
	        
	            
	                
	                    
	                        NON_NULL
	                    
	                
	            
	        
	    
	


你可能感兴趣的:(json返回数据,属性值为null或空的问题)