codecamp

FastJson 在Spring中使用fastJSON

FastJson 提供了Spring MVC HttpMessageConverter的实现

可在Spring Controller中使用FastJson进行数据的序列化和反序列化

FastJsonConfig配置

<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
    <!-- Default charset -->
    <property name="charset" value="UTF-8" />
    <!-- Default dateFormat -->
    <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss" />
    <!-- Feature -->
    <property name="features">
        <list>
            <value>Your feature</value>
        </list>
    </property>
    <!-- SerializerFeature -->
    <property name="serializerFeatures">
        <list>
            <value>Your serializer feature</value>
        </list>
    </property>
    <!-- Global SerializeFilter -->
    <property name="serializeFilters">
        <list>
            <ref bean="Your serializer filter"/>    
        </list>
    </property>
    <!-- Class Level SerializeFilter -->
    <property name="classSerializeFilters">
        <map>
            <entry key="Your filter class" value-ref="Your serializer filter"/>
        </map>
    </property>
</bean>

HttpMessageConverter配置

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
            <!-- MediaTypes -->
            <property name="supportedMediaTypes">
                <list>
                    <value>application/json</value>
                </list>
            </property>
            <!-- FastJsonConfig -->
            <property name="fastJsonConfig" ref="fastJsonConfig" />
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

<mvc:default-servlet-handler />


Fastjson 定制序列化
Fastjson 处理超大JSON文本
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }