FASTJSON 與 springmvc 整合,FastJsonHttpMessageConverter的配置


之前一直用的是jackson, 偶然接觸到fastjson, 感覺fastjson非常的方便, 不過也在github中看到了不少的坑, 總之有待改進


maven pom

<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.18</version>
</dependency>


spring-mvc.xml

<mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json</value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <value>WriteMapNullValue</value>
                        <value>QuoteFieldNames</value>
                    </list>
                </property>
                <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/>
            </bean>
        </mvc:message-converters>
</mvc:annotation-driven>


以上配置定義了 @responsebody 支持的返回類型, json對空鍵值的處理方式 和 統一的日期返回格式

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章