1. spring-mvc.xml
<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4">
<property name="defaultCharset" value="UTF-8"/>
<property name="supportedMediaTypes">
<list>
<!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
<property name="fastJsonConfig">
<bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
<!-- 默认编码 -->
<property name="charset" value="UTF-8"/>
<!-- 日期格式化 -->
<property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/>
<!-- 序列化配置 -->
<property name="serializerFeatures">
<array value-type="com.alibaba.fastjson.serializer.SerializerFeature">
<!-- 输出key时是否使用双引号,默认为true -->
<value>QuoteFieldNames</value>
<!-- 避免循环引用 -->
<value>DisableCircularReferenceDetect</value>
<!-- 是否输出值为null的字段 -->
<value>WriteMapNullValue</value>
<!-- 数值字段如果为null,输出为0,而非null -->
<value>WriteNullNumberAsZero</value>
<!-- 字符类型字段如果为null,输出为"",而非null -->
<value>WriteNullStringAsEmpty</value>
<!-- list字段如果为null,输出为[],而非null -->
<value>WriteNullListAsEmpty</value>
<!-- boolean字段如果为null,输出为false,而非null -->
<value>WriteNullBooleanAsFalse</value>
<!-- 设置使用文本方式输出日期,fastjson默认是long -->
<value>WriteDateUseDateFormat</value>
<!-- 兼容 IE6 -->
<value>BrowserCompatible</value>
</array>
</property>
<!-- SerializeFilter -->
<property name="serializeFilters">
<list>
<bean class="com.zxk175.ssm.common.util.json.FastJsonValueFilter"/>
</list>
</property>
</bean>
</property>
</bean>
2. FastJsonValueFilter
public class FastJsonValueFilter implements ValueFilter {
/**
* fastjson 值过滤器
*/
@Override
public Object process(Object object, String name, Object value) {
if (value == null)
return "";
return value;
}
}