【问题标题】:How to convert application/atom+xml response to json using rest template如何使用 rest 模板将 application/atom+xml 响应转换为 json
【发布时间】:2020-02-14 10:47:37
【问题描述】:

我正在使用 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 是我的自定义类。从 url,我得到原子格式的响应 &lt;content type="application/xml"&gt;

【问题讨论】:

    标签: json spring-boot resttemplate


    【解决方案1】:

    您可以尝试将AtomFeedHttpMessageConverterRssChannelHttpMessageConverter 添加到rest 模板。 看看代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 2015-02-24
      • 1970-01-01
      相关资源
      最近更新 更多