FastJson tutori...login
FastJson tutorial manual
author:php.cn  update time:2022-04-19 14:33:02

FastJson serialization deserialization method


FastJsonHttpMessageConverter


#FastJson provides the implementation of Spring MVC HttpMessageConverter

    FastJsonHttpMessageConverter for Spring MVC Below 4.2
  • FastJsonHttpMessageConverter4 for Spring MVC 4.2
can be used in Spring Controller Using FastJson for Serialize and Deserialize of data

FastJsonConfig configuration

<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 configuration

<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 />


##