异常信息如下:

JSON parse error: 
Can not deserialize instance of java.lang.String out of START_OBJECT token;
nested exception is com.fasterxml.jackson.databind.JsonMappingException:
Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: java.io.PushbackInputStream@7d1ef454; line: 1, column: 39]
(through reference chain: com.chehejia.aisp.core.result.Result["data"])

我自己的服务去调用别人的服务的时候出现的异常,意思是JSON解析失败,用String类型无法序列化Json对象,先看代码:

三方服务:

    @ApiOperation("下订单")
@PostMapping("/orders")
@ApiResponses({
@ApiResponse(code = MusicCode.MUSIC_VIP_PRODUCT_NOT_EXIST_CODE, message = MusicCode.MUSIC_VIP_PRODUCT_NOT_EXIST_DESC),
@ApiResponse(code = MusicCode.MUSIC_VIP_ORDER_CODE_IS_REPEAT_CODE, message = MusicCode.MUSIC_VIP_ORDER_CODE_IS_REPEAT_DESC)}
)
public Result<String> addOrders(@Valid @RequestBody OrderForm form) {
VipProduct vipProduct = vipService.getVipProductByProdCode(form.getProdCode());
if(vipProduct==null){
return Results.failure(MusicCode.MUSIC_VIP_PRODUCT_NOT_EXIST);
}

我的代码:


/**
* @Author: 保密哈哈
* @Description:
* @Date: 2019/6/4 15:40
* @Modified By:
*/
@FeignClient("保密-保密-hmi")
public interface CompensationOrderService {
/**
* 音乐服务下单
* @param form
* @return
*/
@PostMapping(value = "/保密/保密/保密/orders")
@ResponseBody
Result<String> addOrders(@Valid @RequestBody OrderForm form,
@RequestHeader(value = "保密-Token")String token,
@RequestHeader(value = "X-保密-Deviceid")String deviceid);

因为我是通过Fegin调用另一方服务,因为另一个服务调用的接口的返回参数是 Result<String>,所以,我保持了我的接收参数是 Result<String>,  我天真的认为只要完全保持一致就可以,实际上是不行的,传过来的是个Json,所以String是无法解析的,除非是JSon形式的字符串,可行的方法是先用超类Object看看能否接收,并且接收到的是什么参数,然后再解析。

JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of j的更多相关文章

  1. JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc

    代码程序: @PostMapping("selectById") @ResponseBody public Result selectById(@RequestBody int i ...

  2. Jackson错误:Can not deserialize instance of java.lang.String out of START_OBJECT token

    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not des ...

  3. HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite

    org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r ...

  4. 解决用户自生成meta导入kylin后报错问题Can not deserialize instance of java.lang.String[] out of VALUE_STRING token

    报错栈: -- ::, ERROR [http-bio--exec-] cube.CubeManager: : Error during load cube instance, skipping : ...

  5. Could not read document: Can not deserialize instance of java.lang.String out of START_ARRAY

    线上问题: { "timestamp": "1544510665", "status": 400, "error": & ...

  6. 记一次接口调试错误: {"timestamp":"2019-09-11T03:04:30.036+0000","status":500,"error":"Internal Server Error","message":"Could not write JSON: Object is null; nested exception is com.fasterxml.jackson

    接口测试中用postman测试返回是正常的,但是使用其他人去调用就出错了,找了半天,才想起来使用了nginx,用于端口的代理转发.然后根据错误信息发现json格式的某个字段为null,结合日志中的报文 ...

  7. 400 bad Request: JackSon将json串转成List<Object>,异常com.fasterxml.jackson.databind.JsonMappingException

    最近遇到的400, 以前总以为 400 就是参数不匹配造成的,直到今天遇到这个问题 控制台报错如下:  com.fasterxml.jackson.databind.JsonMappingExcept ...

  8. JSON parse error: default constructor not found. class java.time.YearMonth; nested exception is com.alibaba.fastjson.JSONException: default constructor not found. class java.time.YearMonth

    java8新出的YearMonth可以方便的用来表示某个月.我的项目中使用springmvc来接收YearMonth类型的数据时发现 x-www-from-urlencoded 格式的数据可以使用&q ...

  9. Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)

    有一次从服务器解析获取到的Json字符串突然报了这个异常,由于这个json是从 php页面上推送过来的,当时就查是不是由于编码问题引起的,所以就上网搜了,网上大部分都是说由于utf-8的bom头引起的 ...

随机推荐

  1. [RN] React Native 下实现底部标签(不支持滑动切换)

    底部标签是现在App的基本菜单实现 下面分别用 createBottomTabNavigator 和 createMaterialBottomTabNavigator 两种方法分别实现底部菜单 但此两 ...

  2. REdis主从复制之repl_backlog

    目录 目录 1 1. 前言 1 2. 配置项 1 3. redisServer 2 4. feedReplicationBacklog-写repl_backlog 3 5. addReplyRepli ...

  3. Pandas的基本用法

    Pandas是使用python进行数据分析不可或缺的第三方库.我们已经知道,NumPy的ndarray数据结构能够很好地进行数组运算,但是当我们需要进行为数据添加标签,处理缺失值,对数据分组,创建透视 ...

  4. 前端微信小程序电影类仿淘票票微信小程序

    需求描述及交互分析设计思路和相关知识点电影界面顶部页签切换效果设计正在热映界面布局设计即将上映界面布局设计电影详情页设计我的界面列表导航设计登录设计 相关知识点(1)swiper滑块视图容器组件,可以 ...

  5. Web前端鼠标悬停实现显示与隐藏效果

    css定义,偏移量,相对定位,绝对定位 显示与隐藏 二维码相对于微信图标定位 鼠标悬停微信图标上显示 鼠标离开微信图标时隐藏 什么是定位,就是定义网页标签在运行时显示的位置 css提供Position ...

  6. mysql 通配符%以及_

    %匹配任意长度 _ 匹配单个字符 mysql> select * from table1; +----------+------------+-----+-------------------- ...

  7. 大名鼎鼎的RPC和MQ到底有啥区别和联系

    RPC(Remote Procedure Call)远程过程调用,主要解决远程通信间的问题,不需要了解底层网络的通信机制. RPC框架 知名度较高的有Thrift(FB的).dubbo(阿里的). R ...

  8. hdu1237 简单计算器[STL 栈]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1237 题干 代码和解释 解本题时使用了STL 栈,要记得使用#include<stack>. 解本题时使用了isdigit()函 ...

  9. 回顾idea快捷键

    F9            resume programe 恢复程序 Alt+F10       show execution point 显示执行断点 F8            Step Over ...

  10. kafka发送超大消息设置

    最近开发一cdc框架,为了测试极端情况,需要kafka传递100万条数据过去,1个G左右,由于其他环节限制,不便进行拆包(注:测下来,大包走kafka不一定性能更好,甚至可能更低). 测试百万以上的变 ...