No converter found for return value of type: class com.alibaba.fastjson.JSON解決辦法


默認情況下,springMVC的@ResponseBody返回的是String類型,如果返回其他類型則會報錯。
使用fastjson的情況下,在springmvc.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>
<value>application/xml;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

在pom.xml引入依賴:

<dependency>

          <groupId>com.alibaba</groupId>

          <artifactId>fastjson</artifactId>

          <version>1.2.47</version>

</dependency>

<dependency>

          <groupId>com.fasterxml.jackson.core</groupId>

          <artifactId>jackson-core</artifactId>

          <version>2.7.3</version>

</dependency>

<dependency>

          <groupId>com.fasterxml.jackson.core</groupId>

          <artifactId>jackson-databind</artifactId>

          <version>2.7.3</version>

</dependency>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM