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

基礎

  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.com/blog/aoyouzi-2153707
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章