openfeign远程调用接口报错:feign.codec.DecodeException: Error while extracting response for type
错误信息:feign.codec.DecodeException: Error while extracting response for type [java.util.List<xxxx.xxxx..UserComponentRes>] and content type [application/json;charset=UTF-8]; nested exception is or
·
错误信息:
feign.codec.DecodeException: Error while extracting response for type [java.util.List<xxxx.xxxx..UserComponentRes>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.ArrayList<xxxx.xxxx..UserComponentRes>` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList<xxxx.xxxx..UserComponentRes>` from Object value (token `JsonToken.START_OBJECT`)
at [Source: (ByteArrayInputStream); line: 1, column: 1]
通过openfeign日志可用看到调用的返回结果如下:
{"data":[{"count":10,"userLevel":"1"},{"count":4,"userLevel":"2"},{"count":4,"userLevel":"3"},{"count":1,"userLevel":"4"}],"errcode":"0","errmsg":"ok","version":"1"}
这样的返回结果是我们自己使用ApiResult结果集封装的,所以报错。
修改前:
@PostMapping("/userComponent")
public ApiResult<List<UserComponentRes>> userComponent(){
List<UserComponentRes> userComponent = userDetailService.getUserComponent();
return ApiResult.successMsg(userComponent,"1");
}
修改后:
@PostMapping("/userComponent")
private List<UserComponentRes> userComponent(){
List<UserComponentRes> userComponent = userDetailService.getUserComponent();
return userComponent;
}
删除ApiResult封装后返回的结果如下:
[{"count":10,"userLevel":"1"},{"count":4,"userLevel":"2"},{"count":4,"userLevel":"3"},{"count":1,"userLevel":"4"}]
这样就可以正常的被我们调用了。
更多推荐
已为社区贡献1条内容
所有评论(0)