Spring MVC 4.2+ 整合配置fastjson 1.2.11+

来源:互联网 发布:java调用action的方法 编辑:程序博客网 时间:2024/05/09 14:55

由于本人有严重的版本洁癖,所有的框架之类都用最新版本,虽然网上的旧的配置能运行,但是已经打上了Deprecated的注解,于是自己动手配了一下,有跟我一样有版本洁癖的童鞋可以采用

上代码

<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
<property name="serializerFeatures">
<array>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
</array>
</property>
</bean>

<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
<property name="fastJsonConfig" ref="fastJsonConfig"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

不过这种方式目前有个问题 就是只要是写@ResponseBody注解的,它都接管解析,导致我手动拼写的json字符串也会被它再转一次,变成了纯字符串

0 0
原创粉丝点击