原报错信息:
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList<>` from Object value (token `JsonToken.START_OBJECT`)
解决办法:
Feign接口中返回的是一个List而不是一个Object,报了这个错。是Jackson默认不支持序列化List,需要加ACCEPT_SINGLE_VALUE_AS_ARRAY配置:
spring:
jackson:
deserialization:
ACCEPT_SINGLE_VALUE_AS_ARRAY: true
其他办法:
- 使用注解:
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
- 在代码中开启:
ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);