如何使用rest模板将application / atom + xml响应转换为json

时间:2019-10-17 13:29:47

标签: json spring-boot resttemplate

我正在使用atom / xml,我需要将其转换为java对象。 代码如下,我遇到转换错误

代码:

 ResponseEntity<BusinessPartner> response = restTemplate.exchange(url + "/BP_HEADERSet('100000010')", HttpMethod.GET, entity, BusinessPartner.class);

错误:

"message": "Could not extract response: no suitable HttpMessageConverter found for response type [class com.leaseplan.insuranceaccounting.models.BusinessPartner] and content type [application/atom+xml;charset=utf-8;type=entry]",

BusinessPartner是我的自定义类。从网址中,我得到的响应是原子格式<content type="application/xml">

1 个答案:

答案 0 :(得分:0)

您可以尝试将AtomFeedHttpMessageConverterRssChannelHttpMessageConverter添加到休息模板。 看一下代码:

@Bean
public RestTemplate restTemplate(RestTemplateBuilder templateBuilder) {
    return templateBuilder
            .additionalMessageConverters(
                    new AtomFeedHttpMessageConverter(), 
                    new RssChannelHttpMessageConverter())
            .build();
}