SpringMVC JackSon null属性不显示

转自:http://blog.csdn.net/mlz_2/article/details/52229456

spring+springmvc+jackson

如果返回的是List,而ObjectClass对象的某个属性值是null,此时不返回这个属性。


POM

[html]  view plain  copy
 
  1. <dependency>  
  2.     <groupId>com.fasterxml.jackson.coregroupId>  
  3.     <artifactId>jackson-coreartifactId>  
  4.     <version>${jackson.version}version>  
  5. dependency>  
  6.   
  7. <dependency>  
  8.     <groupId>com.fasterxml.jackson.coregroupId>  
  9.     <artifactId>jackson-databindartifactId>  
  10.     <version>${jackson.version}version>  
  11. dependency>  

覆盖默认的

[html]  view plain  copy
 
  1. <mvc:annotation-driven>  
  2.     <mvc:message-converters>  
  3.         <bean  
  4.             class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
  5.             <property name="objectMapper" ref="objectMapper" />  
  6.         bean>  
  7.     mvc:message-converters>  
  8. mvc:annotation-driven>  


[html]  view plain  copy
 
  1. <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">  
  2.         <property name="dateFormat">  
  3.             <bean class="java.text.SimpleDateFormat">  
  4.                 <constructor-arg>  
  5.                     <value>yyyy-MM-dd HH:mm:ssvalue>  
  6.                 constructor-arg>  
  7.             bean>  
  8.         property>  
  9.         <property name="serializationInclusion">  
  10.             <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULLvalue>  
  11.         property>  
  12.     bean>  

你可能感兴趣的:(SpringMVC JackSon null属性不显示)