异常信息如下:

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. pgloader 学习(一)支持的特性

    pgloader 是一个不错的多种格式数据同步到pg 的工具,pgloader 使用postrgresql 的copy 协议进行高效的数据同步处理 特性 加载文件到内容pg 多种数据源格式的支持 cs ...

  2. LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力

    二次联通门 : LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 /* LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 叫做计算几 ...

  3. 深入浅出的Java网络通信

    已经发表个人公众号 代码展示 package two; import java.io.BufferedReader; import java.io.InputStreamReader; import ...

  4. C语言第一篇博客

    你对网络专业或者计算机专业了解是怎样? 进行网络安全,防止信息泄露. 你了解C语言么?C语言主要应用有哪些? C语言简言之就是一门计算机的编程语言. C语言主要应用于应用软件,服务器端开发,系统软件和 ...

  5. Brexit Gym - 101490C

    题目链接:Brexit vector的使用(vector存边),巧用queue,相当于Bfs /* */ # include <iostream> # include <cstdio ...

  6. vuex如何实现数据持久化,刷新页面存储的值还存在

    1.安装: npm install vuex-persistedstate --save 2.找到store/index.js import Vue from 'vue' import Vuex fr ...

  7. ldap和phpldapadmin的安装部署

    LDAP 安装 一.安装LDAP 1. 安装包 yum install openssl-devel gcc libtool-ltdl-devel -y yum install openldap-ser ...

  8. Java_jdbc 基础笔记之八 数据库连接(写一个查询Student对象的方法)

    public Student getStudent(String sql, Object... args) { // 查询Student对象 Student stu = null; Connectio ...

  9. 解决vs2010按ctrl+f5,调试窗口一闪而过的方法

    vs2010调试按F5与按Ctrl+F5有什么区别 Ctrl F5测试运行后不自动推出控制台,直接按F5会自动退出去 解决vs2010按ctrl+f5,调试窗口一闪而过的方法 http://hi.ba ...

  10. IDEA2019.2.1中文乱码解决

    写在前面 太晚了, 长话短说, idea更新到2019.2.1, 项目任何地方输入中文都是乱码, 修改编码UTF-8依然如此.参考https://blog.csdn.net/chenjk10/arti ...