springMVC,json视图,返回的json数据有null值,怎么过滤成空串

<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自动变成空串

第1个回答  推荐于2018-05-10
自己构建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>本回答被网友采纳
第2个回答  2012-05-15
string.replaceAll(":null", ":\"\"")
思路是这样,写法细节需调试

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网