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

编程知识 更新时间:2023-04-05 06:31:32

基础

  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

本文发布于:2023-04-05 06:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/0a0f3e4d1cc3be09dd59a44fc8b1275e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:application   type   Content   json   supported

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 45290文章数
  • 14阅读数
  • 0评论数