Caused by: org.springframework.web.client.RestClientException: Error while extracting response for t

博客讲述了在使用Spring Cloud Alibaba的Feign组件时遇到的一个问题,即接收到三方服务的成功响应,但在反序列化成特定对象时失败。问题在于返回的数据是一个数组,而预期的是单个对象。解决方案是将返回类型调整为List。
摘要由CSDN通过智能技术生成

spring cloud alibaba 三方请求收到处理成功,但是自己接收失败

feign.codec.DecodeException: Error while extracting response for type [com.yxkj.netplus.netcore.result.Result<com.yxkj.netplus.yxdllapi.response.MzNoPayResponse>] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 244] (through reference chain: com.yxkj.netplus.netcore.result.Result["data"])
。。。
Caused by: org.springframework.web.client.RestClientException: Error while extracting response for type [com.yxkj.netplus.netcore.result.Result<com.yxkj.netplus.yxdllapi.response.MzNoPayResponse>] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 244] (through reference chain: com.yxkj.netplus.netcore.result.Result["data"])
 
Caused by: org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 244] (through reference chain: com.yxkj.netplus.netcore.result.Result["data"])
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.yxkj.netplus.yxdllapi.response.MzNoPayResponse` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 244] (through reference chain: com.yxkj.netplus.netcore.result.Result["data"])
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)

问题原因:
就是返回的数据和解析的泛型 对不上,实际是 list 而使用的是 T
Cannot deserialize instance of com.yxkj.netplus.yxdllapi.response.MzNoPayResponse out of START_ARRAY token:
翻译: 不能反序列化实例 XXXXX 对象 开始数组越界。 提示的很清楚。

我这边三方接口访问正常 原因是坑爹的泛型:
提供数据方代码:

public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;  // 重点是这个 泛型 T

实际数据格式是: 这里的 Data 是一个 数组也就是 list

{
  "code": 200,
  "msg": "成功",
  "data": [
    {
      "CDJH": "2104000008",
      "IFYLX": "1",
    }
  ],
  "executetime": 0,
  "timestamp": "2021-04-27 16:23:15"
}

而返回值写的是:
这里要注意 这里返回的一个 T 类型 , 但是坑爹的是 自己调用 居然还能返回正确。
在这里插入图片描述
正确的写法是: List
在这里插入图片描述

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值