不用jackson而用fastjson 一样可以支持json的解析

这样的话需要新增一个配置

<!-- if you use annotation you must configure following setting -->
	<!-- <mvc:annotation-driven />  -->
	<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">  
        <mvc:message-converters register-defaults="true">  
            <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->  
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">  
                <constructor-arg value="UTF-8" />  
            </bean>  
            <!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">   
                <property name="prettyPrint" value="true"/> </bean> -->  
            <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
                <property name="supportedMediaTypes" value="application/json;charset=UTF-8" />  
                <property name="features">  
                    <array value-type="com.alibaba.fastjson.serializer.SerializerFeature">  
                        <value>DisableCircularReferenceDetect</value>  
                    </array>  
                </property>  
            </bean>  
        </mvc:message-converters>  
    </mvc:annotation-driven>
    
    
     <!-- 解决 fastjson 循环引用 -->
    <bean id="DisableCircularReferenceDetect" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">  
        <property name="staticField" value="com.alibaba.fastjson.serializer.SerializerFeature.DisableCircularReferenceDetect"></property>  
    </bean>  
    <!-- REST中根据URL后缀自动判定Content-Type及相应的View -->  
    <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">  
        <property name="ignoreAcceptHeader" value="true" />  
        <property name="defaultContentType" value="application/json" />  
        <property name="mediaTypes">  
            <value>  
                json=application/json  
                xml=application/xml  
            </value>  
        </property>  
    </bean>  


pom文件的引用

		<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.40</version>
		</dependency>


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值