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
在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐