Content-Type 'application/json;charset=UTF-8' is not supported异常解决
Content-Type 'application/json;charset=UTF-8' is not supported异常解决
前提:确定不是因为Content-Type导致的异常,controller层有注解@RequestBody。
报错详情:

确定不是因为缺少Jackson依赖或者版本过低:

注意到报错信息上边有一条警告日志:
.c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.xxx.ddd.api.OpenApiRequest<com.xxx.admin.api.insuranceProductConfig.models.request.UpdateComponentByComponentCodeReq>]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Failed to call `setAccess()` on Constructor 'java.util.Objects' (of class `java.util.Objects`) due to `java.lang.reflect.InaccessibleObjectException`, problem: Unable to make private java.util.Objects() accessible: module java.base does not "opens java.util" to unnamed module @77eca502
显而易见是因为执行反序列化出错,看到module java.base does not "opens java.util" to unnamed module
基本可以确定是jdk17引起的问题,在jvm启动参数加上--add-opens java.base/java.util=ALL-UNNAMED
后,发现真正报错原因如下:

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.Objects` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('map')
at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 56, column: 16] (through reference chain: com.xxx.ddd.api.OpenApiRequest["requestParams"]->com.xxx.admin.api.insuranceProductConfig.models.request.UpdateComponentByComponentCodeReq["components"]->java.util.ArrayList[0]->com.xxx.admin.api.insuranceProductConfig.models.valueObject.config.ComponentItem["context"]->java.util.LinkedHashMap["map"])
经排查定位到入参对象引用的一个java对象,在网上找解决方法是增加一个readValue的构造函数,如:https://blog.csdn.net/qq_30162239/article/details/86647164,要么对不想序列化的field加@JsonIgnore
注解。
本博客内容仅供个人学习使用,禁止用于商业用途。转载需注明出处并链接至原文。
标签:
bug记录
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?