异常信息如下:

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. P4279 【[SHOI2008]小约翰的游戏】

    我怎么什么都不会啊\(QAQ\)博弈论怎么和期望一样玄学啊\(QAQ\) 我们分几种情况讨论: \(Case1\):只有一堆且为1,那么后手胜利 \(Case2\):每一堆都是1,那么只需要判断奇偶性 ...

  2. javascript之反柯里化uncurrying

    使用方法: // 使用 var push=Array.prototype.push.uncurrying(); var obj={ "length": 1, "0&quo ...

  3. 「SNOI2019」积木

    传送门 Description 有一块\(n\)行\(m\)列的网格板, \(n,m\)都是奇数.网格上平铺着一些\(1*2\)的积木.积木可以旋转,不能重叠.网格板上只有一格的空位. 你可以做两种操 ...

  4. Make sure you've included captcha.urls as explained in the INSTALLATION section on

    原因:django-simple-captcha将客户端编号与验证码默认存储在数据库中 解决办法: python manage.py migrate

  5. SQL Delta实用案例介绍

    概述 本篇文章主要介绍SQL DELTA的简单使用.为了能够更加明了的说明其功能,本文将通过实际项目中的案例加以介绍. 主要容 Ÿ   SQL DELTA 简介 Ÿ   创建SQL DELTA项目 Ÿ ...

  6. Python面向对象编程核心思想

    原文地址https://blog.csdn.net/weixin_42134789/article/details/80194788 https://blog.csdn.net/happyjxt/ar ...

  7. Spring Boot-intellij idea导入方式搭建SpringBoot

    Spring Boot概念 从最根本上来讲,Spring Boot就是一些库的集合,它能够被任意项目的构建系统所使用.简便起见,该框架也提供了命令行界面,它可以用来运行和测试Boot应用.框架的发布版 ...

  8. PostgreSQL体系架构与内存结构

    PostgreSQL体系架构 PostgreSQL的内存结构

  9. [转]Vue-Devtools安装配置教程(献给伸手党)

    原文地址:https://blog.csdn.net/weixin_38654336/article/details/80790698 可以先看视频教程:链接 最简便的方法是用FQ来通过google应 ...

  10. uni-app打包程序 Hbuilder X 用自有证书 苹果证书打包 ios App、用DCloud公用证书打包Android APP

    Android用HBuilder的DCloud公用证书即可 HBuilderX  uni-app打包成apk安装到手机首先要登录,没有帐号可以注册,接着点击运行—原生App-云打包,配置完后点击打包, ...