2018-08-15

spring 注解 @ResponseBody 返回JSON 能不能设置他不返回为 null 的值


Searched by:
@responsebody without null value
https://www.google.com.sg/search?q=%40responsebody+without+null+value&oq=%40responsebody+without+null+value&aqs=chrome..69i64.7166j0j1&sourceid=chrome&ie=UTF-8


Reference URL:
https://segmentfault.com/q/1010000002522525


设置jackson忽略null

<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper">
                <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                    <property name="serializationInclusion">
                        <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
                    </property>
                </bean>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>




No comments:

Google Referrals