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相关推荐

  1. 前端无法反序列化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 ...

  2. 【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 原因: 解决办法 总结:仰 ...

  3. Springboot文件上传报错:failed to convert java.lang.String to org.springframework.util.unit.DataSize

    springboot2.1.2版本文件上传报错,我上传的是一个18M的音频,默认的配置应该是超过10M的文件就会报错,所以我将配置修改为: spring:servlet:multipart:enabl ...

  4. 头条穿山甲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 ...

  5. myeclipse中启动tomcat是报错如下: Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/web/contex

    myeclipse中启动tomcat是报错如下: Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/web/context ...

  6. IDEA运行redis多线程访问报错Exception in thread “main“ java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

    错误样式: 解决方案: 下载两个JAR包即可,同样的代码我在MyEclipse中运行就不报错,可能是IDEA缺少这两个JAR包吧,而ME本身自带了 托管下载地址:Central Repository: ...

  7. jenkins配置报错,javax.servlet.ServletException: java.lang.RuntimeException: ssh executable not found.

    jenkins定时构建配置时报javax.servlet.ServletException: java.lang.RuntimeException: ssh executable not found. ...

  8. 【亲测有效】如何解决Hadoop运行jar包 报错Exception in thread “main“ java.lang.ClassNotFoundException: /input

    报错解释 字面意思就是我要运行这个jar但是Java无法找到主类 试错过程 你可能会在这里添加主类,但是还是不行.你可能没辙了. 解决办法 <build><finalName> ...

  9. Mybatis报错: Error querying database. Cause: java.lang.NumberFormatException: For input string: “A“

    报错信息:Error querying database. Cause: java.lang.NumberFormatException: For input string: "A" ...

最新文章

  1. vconsole插件_手机前端开发调试利器 – vConsole
  2. 新年红包封面来了,3000万份红包封面来啦!到点直领!
  3. SAP CRM和SAP Hybris的action profile
  4. 算法设计与分析——回溯法——装载问题
  5. 神经网络的SGD、Momentum、AdaGrad、Adam最优化方法及其python实现
  6. MyBatis的概述及使用
  7. directUI的心得
  8. C# RangeHelper
  9. 新买的Olmpus 7070,5.1照得几张照片
  10. 2012、12、17
  11. mysql导入报错1071_导入sql文件报错:1071 Specified key was too long; max key length is 767 bytes...
  12. windows7蓝牙怎么打开_PC版微信v2.7.0曝光:支持电脑上打开小程序
  13. Python项目开发基础 -- 函数参数与数据库连接参数
  14. html网页设计优秀作品和代码,从优秀的网页设计作品中学排版和配色
  15. 零基础搭建电影网站教程——一、域名与服务器
  16. java免费获取物流信息
  17. Android 设置铃声——给app设置自定义铃声功能
  18. 查看数据库信息(一)
  19. bzoj 1022: [SHOI2008]小约翰的游戏John(anti-nim)
  20. 如何让DIV元素永远居中显示

热门文章

  1. Android 网星工具箱Beta版
  2. vue插件瀑布流vue-masonry(带源码)
  3. 基于android的学单词app
  4. [mac]添加系统自带辞典或下载的词典包
  5. 汽车销量查询小助手(小程序)销量趋势图功能及代码知识分享
  6. 计算机作业我家乡的变化英语作文,我的变化英语作文3篇
  7. 电话程控交换机安装经验
  8. Object Detection in 20 Years: A Survey 20年间的目标检测:综述
  9. Qt多人协作项目执行方案
  10. uefi装完系统后无法引导_不重装系统修改引导方式为UEFI模式