[英]MappingJackson2HttpMessageConverter from xml to java configuration Malfunctioning
I change my application from a xml-based configuration to a java-based configuration. 我将应用程序从基于xml的配置更改为基于Java的配置。 In the java-based configuration, I get below error, which I don't get in the xml-based configuration.
在基于Java的配置中,出现以下错误,在基于xml的配置中未出现此错误。 What I'm missing in the java configuration?
我在Java配置中缺少什么? Please assist.
请协助。
The method throwing this error: 抛出此错误的方法:
response = restTemplate.exchange(uri.toUri(), HttpMethod.GET, entity, UserProfiles.class);
The error : 错误 :
nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.mycompany.wsg.profile.model.v26.gen.ListItemDef: no String-argument constructor/factory method to deserialize from String value ('U-71155f93-8413-457c-a045-256dc6ab0a93@poims001.ucc2.ucc.stgsip.t-mobile.com')
The issue was definitely the java configuration. 问题绝对是java配置。 Here's how I resolve it:
这是我的解决方法:
public class SpringWebConfig extends WebMvcConfigurationSupport {
....//unrelated configuration here
@Bean
public RestTemplate restTemplate()
{
RestTemplate restTemplate = new RestTemplate(httpClientFactory());
restTemplate.setMessageConverters(getMessageConverters());
return restTemplate;
}
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
converters.add(createXmlHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
super.configureMessageConverters(converters);
}
private HttpMessageConverter<Object> createXmlHttpMessageConverter() {
MarshallingHttpMessageConverter xmlConverter =
new MarshallingHttpMessageConverter(jaxb2Marshaller(), jaxb2Marshaller());
return xmlConverter;
}
}
Hope this helps someone else 希望这对别人有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.