SpringMVC序列化问题

x33g5p2x  于2022-03-02 转载在 Spring  
字(1.3k)|赞(0)|评价(0)|浏览(662)

问题描述

做练习的时候定义了一个练习的接口,正常情况下应该返回数据。

但是却出现了下面的异常,异常如下:

  1. HTTP Status 500 - No converter found for return value of type: class com.domain.Result
  2. type Exception report
  3. message No converter found for return value of type: class com.domain.Result
  4. description The server encountered an internal error that prevented it from fulfilling this request.
  5. exception
  6. org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.domain.Result
  7. org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:226)
  8. .......

解决方式

经过分析,问题是在于没有加载序列化的依赖,因为这个项目是基础的SSM项目,没有Springboot集成,所以出现这个问题的时候我有一丝懵逼,一度怀疑mvc的配置文件没有配置好。

具体的解决方式如下

  1. <dependencies>
  2. <dependency>
  3. <groupId>com.fasterxml.jackson.core</groupId>
  4. <artifactId>jackson-core</artifactId>
  5. <version>2.9.6</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.fasterxml.jackson.core</groupId>
  9. <artifactId>jackson-annotations</artifactId>
  10. <version>2.9.6</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.fasterxml.jackson.core</groupId>
  14. <artifactId>jackson-databind</artifactId>
  15. <version>2.9.6</version>
  16. </dependency>
  17. </dependencies>

添加上jackson三件套就行了。

问题解决。

相关文章