我正在调用第三方API,它以XML格式返回响应。由于我没有创建任何POJO来在我的消费者服务中保存响应,因此我使用java.lang.Object
进行相同的操作。
我收到以下错误。
org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [application/xml]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:126) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:59) ~[spring-cloud-openfeign-core-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:62) ~[spring-cloud-openfeign-core-2.2.5.RELEASE.jar:2.2.5.RELEASE]
我的假客户代码
@FeignClient(value = "SERVICE", url = "https://goog.dummyservice/api1/v1", decode404 = true)
public interface UserFeign {
@GetMapping(value = "/docs/{profile}/{protocol}", consumes = MediaType.APPLICATION_XML_VALUE)
Object getUserData(@RequestHeader("Authorization") String token,
@PathVariable("profile") String profile,
@PathVariable("protocol") String protocol);
}
我想知道如何通过伪装来保持XML响应。
2条答案
按热度按时间ykejflvf1#
FeignClientConfiguration.java
ConsultaClient.java
2lpgd9682#
下面的步骤序列帮助我解决了这个问题:
1 -将jackson-dataformat-xml依赖项添加到pom.xml
2 -在UserFeign.java中添加此自定义配置
}