SpringMVC JackSon null属性不显示

    xiaoxiao2021-03-25  31

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

    spring+springmvc+jackson

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

    POM

    [html]  view plain  copy   <dependency>       <groupId>com.fasterxml.jackson.core</groupId>       <artifactId>jackson-core</artifactId>       <version>${jackson.version}</version>   </dependency>      <dependency>       <groupId>com.fasterxml.jackson.core</groupId>       <artifactId>jackson-databind</artifactId>       <version>${jackson.version}</version>   </dependency>   覆盖默认的

    [html]  view plain  copy   <mvc:annotation-driven>       <mvc:message-converters>           <bean               class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">               <property name="objectMapper" ref="objectMapper" />           </bean>       </mvc:message-converters>   </mvc:annotation-driven>  

    [html]  view plain  copy   <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">           <property name="dateFormat">               <bean class="java.text.SimpleDateFormat">                   <constructor-arg>                       <value>yyyy-MM-dd HH:mm:ss</value>                   </constructor-arg>               </bean>           </property>           <property name="serializationInclusion">               <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>           </property>       </bean>  
    转载请注明原文地址: https://ju.6miu.com/read-50351.html

    最新回复(0)