开发环境
| 名称 | 版本 |
|---|---|
| 操作系统 | Windows 10 X64 |
| JDK | JDK1.8(jdk-8u151-windows-x64) |
| IntelliJ IDEA | IntelliJ IDEA 2018.3 |
| Maven | Maven 3.6.0 |
问题描述
调用接口报错,前端提示
{"code": 400,"message": "DemoConsumer#getUserRole(String) failed and no fallback available."}
后端代码报错为
Caused by: feign.codec.DecodeException: Error while extracting response for type [java.util.List<java.lang.String>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT tokenCaused by: org.springframework.web.client.RestClientException: Error while extracting response for type [java.util.List<java.lang.String>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance ofCaused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT tokenCaused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT tokenat [Source: (PushbackInputStream); line: 1, column: 1]
问题分析
是调用 getUserRole 接口报的错
先看生产者这个接口的定义
/*** 获取用户对应的角色权限** @param userId 用户角色权限* @return List<String>**/@PostMapping("/getUserRole")public List<String> getUserRole(@RequestParam(value = "userId") String userId)
我在 web 项目中调用如下
List<String> roleList = consumer.getUserRole(result.getData().getId());
问题解决
看上去没什么问题,打入断点到上面的代码,发现这里 Id 没有值,导致报错
把 Id 设置有值之后,错误消失,问题解决。