先把报错信息贴出来:
org.springframework.web.client.RestClientException: Error while extracting response for type [com.mi.info.comb.common.x5protocol.core.dto.X5Response<com.mi.info.miim.fs.service.x5.dto.customer.OwnerPageDTO>] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized field "country" (class com.mi.info.miim.fs.service.x5.dto.customer.OwnerInfoDTO), not marked as ignorable; nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "country" (class com.mi.info.miim.fs.service.x5.dto.customer.OwnerInfoDTO), not marked as ignorable (5 known properties: "status", "veCode", "veComName", "veComNameEn", "veComShortName"])
at [Source: (PushbackInputStream); line: 1, column: 112] (through reference chain: com.mi.info.comb.common.x5protocol.core.dto.X5Response["body"]->com.mi.info.miim.fs.service.x5.dto.customer.OwnerPageDTO["records"]->java.util.ArrayList[0]->com.mi.info.miim.fs.service.x5.dto.customer.OwnerInfoDTO["country"])
从下面这行错误信息大致可以看出,有个字段country没找到,导致报错了
ested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "country" (class com.mi.info.miim.fs.service.x5.dto.customer.OwnerInfoDTO)
为啥折腾了很久呢,用的公司的一个框架,看不到请求之后的response中的内容,后来尝试增加了配置,配置主要是用于:json转对象的时候,如果字段找不到,就不赋值,这样不存在的字段直接跳过就好了。配置如下:
package com.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(mappingJackson2HttpMessageConverter());
}
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
converter.setObjectMapper(objectMapper);
return converter;
}
}
问题得到解决,记录一下。