Content type ‘application/json;charset=UTF-8‘ not supported异常的解决过程

ops/2024/12/22 21:07:27/

1.首先说明开发场景

*就是对该json格式数据传输到后台在这里插入图片描述

  • 后台实体类
java">import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;@Data
@TableName("interview_information")
public class InterviewInformationEntity {@TableIdprivate Long id;/*** 应聘人员姓名*/private String name;/*** 应聘人员年龄*/private Integer age;/*** 性别*/private Integer sex;/*** 身份证号码*/private String idCard;/*** 邮箱*/private String mailbox;/*** 简历网页地址*/private String vita;/*** 应聘次数*/private Integer numberJob;/*** 应聘结果(未应聘0,应聘通过1,应聘未通过2)*/private Byte ending;/*** 面试信息表的id(具体的面试结果评分)*/private Long InterviewResultsId;/*** 应聘岗位*/private Long station;/*** 应聘时间*/private Data time;}
  • controller中的代码
java">@RestController
@RequestMapping("/interview")
public class InterviewInformationController extends AbstractController {/*** 应聘人员信息service*/@AutowiredInterviewInformationService informationService;/*** 黑名单service*/@AutowiredInterviewBlacklistService blacklistService;/*** 将应聘人员基本信息存入数据库* @param interviewInformationEntity  应聘人员信息实体类* @return  存储是否成功*/@PostMapping("/setInterviewer")public R setInterviewer( @RequestBody InterviewInformationEntity interviewInformationEntity){//用户是否在黑名单中//获取黑名单List<InterviewBlacklistEntity> blacklistEntities=blacklistService.list(new QueryWrapper<InterviewBlacklistEntity>().eq("interview_static","true"));//用于查看是否获取到黑名单System.out.println("黑名单"+blacklistEntities);//存入黑名单idcardSet<String> blackList=new HashSet<>();blacklistEntities.stream().forEach(a -> {blackList.add(a.getIdCard());});//如果注册者的省份证号在黑名单中,直接报错if (blackList.contains(interviewInformationEntity.getIdCard())){return R.error("对不起,请另寻高就!");}//通过身份证查找是否存在在数据库中InterviewInformationEntity interview1=informationService.findByidCrid(interviewInformationEntity.getIdCard());boolean save;//判断查找的数据是否为空if (Objects.isNull(interview1)){//如果存入的数据未存在数据库中,则直接将用户信息注入到数据库save= informationService.saveOrUpdate(interviewInformationEntity);}else {//如果存入的数据不是空,则对数据库中的信息进行更新//将新存入的信息替换掉老信息存入到数据库中,通过id进行更新interviewInformationEntity.setId(interview1.getId());save = informationService.updateById(interviewInformationEntity);}return save?R.ok():R.error("保存失败");}}
  • 报错数据
java">2024-04-30 09:07:35.474  INFO 25208 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/wedu]   : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-04-30 09:07:35.474  INFO 25208 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-04-30 09:07:35.484  INFO 25208 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 10 ms
2024-04-30 09:07:35.536  WARN 25208 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.wedu.modules.sys.entity.InterviewInformationEntity]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class lombok.Data (of type annotation) as a Bean
2024-04-30 09:07:35.537  WARN 25208 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.wedu.modules.sys.entity.InterviewInformationEntity]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class lombok.Data (of type annotation) as a Bean
2024-04-30 09:07:35.540 ERROR 25208 --- [nio-8080-exec-1] c.w.common.exception.RRExceptionHandler  : Content type 'application/json;charset=UTF-8' not supportedorg.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supportedat org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:225)at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:158)at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131)at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:112)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.wedu.common.xss.XssFilter.doFilter(XssFilter.java:25)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:750)

2.解决

  • 1.首先就是遇见了导包的博客,需要导下面的包,但是经过筛查并不缺
java">        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.1.5.RELEASE</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.58</version></dependency><dependency><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-cbor</artifactId><version>2.9.9</version></dependency>
  • 2.其次遇到了说请求头中缺少下面这个东西
java">ContentType :'application/json'

但是请求头中确实存在该东西
在这里插入图片描述

  • 3.实体类中出现问题
    • 该博客说其实这个问题的根本原因就是实体类中引用了一个没有实现实现Serializable 接口的对象,无法被反序列化,只需要在这个对象上添加@JsonIgnore这个注解即可。
  • 并且该报错已经进行提示了
    博客链接
java">2024-04-30 09:07:35.536  WARN 25208 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.wedu.modules.sys.entity.InterviewInformationEntity]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class lombok.Data (of type annotation) as a Bean
  • 问题就在这
    在这里插入图片描述
  • 随后我将该数据加上@JsonIgnore注解,确实解决之前的问题了,
  • 随后发现存入数据库时,数据类型不对等,然后反应 过来原来是数据类型错了,把时间日期类的Date写成Data,Data是lombok的类无法序列化

http://www.ppmy.cn/ops/26180.html

相关文章

LangChain入门2 RAG详解

RAG概述 一个典型的RAG应用程序,它有两个主要组件&#xff1a; 索引&#xff1a;从源中获取数据并对其进行索引的管道。这通常在脱机情况下发生。检索和生成&#xff1a;在运行时接受用户查询&#xff0c;并从索引中检索相关数据&#xff0c;然后将其传递给模型。 从原始数据…

python Django 的内置权限系统或自定义模型来存储更复杂的角色和权限关系

在 Django 中,管理用户权限和角色通常涉及到使用 Django 的内置权限系统或自定义模型来存储更复杂的角色和权限关系。下面是一个基本的指南,说明如何在 Django 中为后台管理系统分配权限并将其保存在数据库中,同时结合 Vue.js 和 Element UI 作为前端框架。 后端(Django)…

c++11 标准模板(STL)本地化库 - 平面类别(time_get) - 从输入字符序列中解析时间/日期值到 std::tm 中(一)

本地化库 本地环境设施包含字符分类和字符串校对、数值、货币及日期/时间格式化和分析&#xff0c;以及消息取得的国际化支持。本地环境设置控制流 I/O 、正则表达式库和 C 标准库的其他组件的行为。 平面类别 从输入字符序列中解析时间/日期值到 std::tm 中 std::time_get …

深入剖析Tomcat(五) 剖析Servlet容器并实现一个简易Context与Wrapper容器

上一章介绍了Tomcat的默认连接器&#xff0c;后续程序都会使用默认连接器。前面有讲过Catalina容器的两大块内容就是连接器与Servlet容器。不同于第二章的自定义丐版Servlet容器&#xff0c;这一章就来探讨下Catalina中的真正的Servlet容器究竟长啥样。 四种容器 在Catalina中…

短视频生成背景文字工具(前端工具)

过年这两天有些无聊就刷刷抖音&#xff0c;刷着刷着自己也蠢蠢欲动&#xff0c;想发上几个&#xff0c;可是却找不到合适自己的模板。由于个人喜欢一些古诗文之类的&#xff0c;所以自己简单的编写了一个小工具&#xff0c;如下图&#xff1a; 当设置好了之后&#xff0c;将浏…

web server apache tomcat11-30-The Tomcat JDBC Connection Pool

前言 整理这个官方翻译的系列&#xff0c;原因是网上大部分的 tomcat 版本比较旧&#xff0c;此版本为 v11 最新的版本。 开源项目 从零手写实现 tomcat minicat 别称【嗅虎】心有猛虎&#xff0c;轻嗅蔷薇。 系列文章 web server apache tomcat11-01-官方文档入门介绍 web…

香港BGP服务器和香港双线服务器的区别

香港BGP服务器和香港双线服务器在网络架构和连接方式上有一些区别&#xff0c;主要体现在以下几个方面&#xff1a; 网络连接方式&#xff1a; 香港BGP服务器采用BGP(边界网关协议)技术&#xff0c;通常连接到多个不同的网络服务提供商(ISP)&#xff0c;并通过BGP协议动态选择最…

图计算浅谈:主流图存储引擎/图搜索算法

在数据关联与复杂网络越来越突显其价值的今日&#xff0c;图数据库&#xff08;Graph Database&#xff09;逐渐成为在大数据领域不可或缺的一部分。图数据库强调数据项之间的关系&#xff0c;它不仅能存储大量的顶点&#xff08;Vertex&#xff09;和边&#xff08;Edge&#…