基础

  SpringBoot接受到http请求后,会根据content-type来判断请求的数据格式,进而利用HttpMessageConverter将数据解析成特定的类型。对应JSON格式的数据,SpringBoot默认使用jackson进行数据的序列化/反序列化;

可能原因

  • 原因1:缺少jackson相关的jar包
<dependency>
   <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.9</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.9</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.9.9</version>
</dependency>

对于SpringBoot, 添加spring-boot-starter-web后会自动引入这些依赖;

  1. 原因2:没有解析JSON格式的Converter,比如默认的MappingJackson2HttpMessageConverter(利用jackson),或者FastJsonHttpMessageConverter(利用fastjson);
  2. 原因3:Converter反序列化解析JSON时失败;

参考:

  1. https://www.iteye/blog/aoyouzi-2153707

更多推荐

Content type 'application/json;charset=UTF-8' not supported