springMVC,json视图,返回的json数据有null值,怎么过滤成空串
<beanclass="org.springframework.web.servlet.view.json.MappingJacksonJsonView"><proper...
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="encoding">
<value type="org.codehaus.jackson.JsonEncoding">UTF8</value>
</property>
<property name="contentType" value="application/json;charset=UTF-8"/>
</bean>
json:
{"s":{"userId":"1","userName":"测试","passWord":"3","list":null,"dep":null,"date":1325347200000},"userForm":{"userId":"1","userName":"测试","passWord":"3","list":null,"dep":null,"date":1325347200000}}
里面有null值,怎么配置,才能让null自动变成空串 展开
<property name="encoding">
<value type="org.codehaus.jackson.JsonEncoding">UTF8</value>
</property>
<property name="contentType" value="application/json;charset=UTF-8"/>
</bean>
json:
{"s":{"userId":"1","userName":"测试","passWord":"3","list":null,"dep":null,"date":1325347200000},"userForm":{"userId":"1","userName":"测试","passWord":"3","list":null,"dep":null,"date":1325347200000}}
里面有null值,怎么配置,才能让null自动变成空串 展开
2个回答
展开全部
自己构建ObjectMapper注入进去,在ObjectMapper中设置NOT_NULL不转换
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="extractValueFromSingleKeyModel" value="true" />
<property name="objectMapper">
<bean class="org.codehaus.jackson.map.ObjectMapper">
<property name="serializationInclusion">
<value type="org.codehaus.jackson.map.annotate.JsonSerialize$Inclusion">NON_NULL</value>
</property>
</bean>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="extractValueFromSingleKeyModel" value="true" />
<property name="objectMapper">
<bean class="org.codehaus.jackson.map.ObjectMapper">
<property name="serializationInclusion">
<value type="org.codehaus.jackson.map.annotate.JsonSerialize$Inclusion">NON_NULL</value>
</property>
</bean>
</property>
</bean>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询