Rest请求使用Jackson反序列化报错,Cannot deserialize instance of `java.lang.String` out of START_OBJECT toke
Rest接口,使用Jackson作为json转换器,后端接收请求的时候报错了,异常信息:
JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
at [Source: (PushbackInputStream); line: 1, column: 138] (through reference chain: com.xxx.TradeDto["body"]->com.xxx.dto.FxsFsDto["txDt"])] [http-nio-9008-exec-10]
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
at [Source: (PushbackInputStream); line: 1, column: 138] (through reference chain: com.xxx.TradeDto["body"]->com.xxx.dto.FxsFsDto["txDt"])
请求报文:
{"body":{"txType":"01","nearDeliveryType":"01","txDt":{}}}
异常信息是很详细、明确的,
Cannot deserialize instance of `java.lang.String` out of START_OBJECT
是说无法将字段,从START_OBJECT(Object类型,即对象)转换为String(字符串类型)
(through reference chain: com.xxx.TradeDto["body"]->com.xxx.dto.FxsFsDto["txDt"])
是说,转换出错的字段,是body字段里的txDt字段。
还包含了类型信息:
com.xxx.TradeDto是整个请求体的类型
body字段是com.xxx.dto.FxsFsDto类型
综上,出错原因是body的txDt字段,请求数据是Object类型,接收方要求的是String类型,不匹配。
问题解决:
将txDt改成字符串
更改后的请求报文:
{"body":{"txType":"01","nearDeliveryType":"01","txDt":""}}
附:
关于Jackson转换,报错信息是很明确的,
比如:Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token
意思是无法将对象转换为列表
Rest请求使用Jackson反序列化报错,Cannot deserialize instance of `java.lang.String` out of START_OBJECT toke相关推荐
- 前端无法反序列化START\u数组标记-JSONCannot deserialize instance of `java.lang.String` out of START_ARRAY toke
前端传参时报错:msg: "JSON parse error: Cannot deserialize instance of java.lang.String out of START_AR ...
- 【java运行报错】Can not set java.lang.String field com.iS.UserEntity.name to java.lang.Class
[java运行报错]Can not set java.lang.String field com.iS.UserEntity.name to java.lang.Class 原因: 解决办法 总结:仰 ...
- Springboot文件上传报错:failed to convert java.lang.String to org.springframework.util.unit.DataSize
springboot2.1.2版本文件上传报错,我上传的是一个18M的音频,默认的配置应该是超过10M的文件就会报错,所以我将配置修改为: spring:servlet:multipart:enabl ...
- 头条穿山甲GroMore广告报错Value pangle of type java.lang.String cannot be converted to JSONObject
接入头条穿山甲广告, 按官网走的, 使用时候大量报错. Value pangle of type java.lang.String cannot be converted to JSONObject ...
- myeclipse中启动tomcat是报错如下: Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/web/contex
myeclipse中启动tomcat是报错如下: Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/web/context ...
- IDEA运行redis多线程访问报错Exception in thread “main“ java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
错误样式: 解决方案: 下载两个JAR包即可,同样的代码我在MyEclipse中运行就不报错,可能是IDEA缺少这两个JAR包吧,而ME本身自带了 托管下载地址:Central Repository: ...
- jenkins配置报错,javax.servlet.ServletException: java.lang.RuntimeException: ssh executable not found.
jenkins定时构建配置时报javax.servlet.ServletException: java.lang.RuntimeException: ssh executable not found. ...
- 【亲测有效】如何解决Hadoop运行jar包 报错Exception in thread “main“ java.lang.ClassNotFoundException: /input
报错解释 字面意思就是我要运行这个jar但是Java无法找到主类 试错过程 你可能会在这里添加主类,但是还是不行.你可能没辙了. 解决办法 <build><finalName> ...
- Mybatis报错: Error querying database. Cause: java.lang.NumberFormatException: For input string: “A“
报错信息:Error querying database. Cause: java.lang.NumberFormatException: For input string: "A" ...
最新文章
- vconsole插件_手机前端开发调试利器 – vConsole
- 新年红包封面来了,3000万份红包封面来啦!到点直领!
- SAP CRM和SAP Hybris的action profile
- 算法设计与分析——回溯法——装载问题
- 神经网络的SGD、Momentum、AdaGrad、Adam最优化方法及其python实现
- MyBatis的概述及使用
- directUI的心得
- C# RangeHelper
- 新买的Olmpus 7070,5.1照得几张照片
- 2012、12、17
- mysql导入报错1071_导入sql文件报错:1071 Specified key was too long; max key length is 767 bytes...
- windows7蓝牙怎么打开_PC版微信v2.7.0曝光:支持电脑上打开小程序
- Python项目开发基础 -- 函数参数与数据库连接参数
- html网页设计优秀作品和代码,从优秀的网页设计作品中学排版和配色
- 零基础搭建电影网站教程——一、域名与服务器
- java免费获取物流信息
- Android 设置铃声——给app设置自定义铃声功能
- 查看数据库信息(一)
- bzoj 1022: [SHOI2008]小约翰的游戏John(anti-nim)
- 如何让DIV元素永远居中显示