我将 JBoss 6.x EAP 与 RestEasy 结合使用。
当我尝试在我的 Web 应用程序中包含 swagger.io 1.5.0 并尝试使用外部 Jersey 休息客户端进行调用时,我注意到它给出了错误,因为由于在 json 转换期间忽略了 @XMLElement(name="some_value"),因此正文请求未得到很好的解析。
这可能是由于 swagger jaxb 库覆盖了 JBoss 提供的库。
这是外部rest客户端的一段代码
// requestObject is a pojo with JAXB annotations
// When using swagger, the field @XmlElement name is ignored, therefore the object is unmashaled with myName instead of my_name as expected
// @XmlElement(name = "my_name"))
// String myName
ClientResponse response;
try {
response = client.resource(requestURI).queryParams(queryParams)
.type(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.post(ClientResponse.class, requestObject);
我尝试包含最新版本的 xml 提供程序,如下所示:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.3</version>
</dependency>
但没有任何改变。
关于如何使用原始 Jackson/jaxb 提供程序进行对象映射有什么建议吗?
最佳答案
最终使用提供的解决方案解决了here
只需在 swagger 库的 dependencyManagement 上添加这组排除即可
<exclusion>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
</exclusion>
关于java - 包含 swagger api 会导致 JBoss EAP 下的 jaxb 提供程序发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39774899/