java - 包含 swagger api 会导致 JBoss EAP 下的 jaxb 提供程序发生冲突

标签 java xml jboss jaxb swagger

我将 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/

相关文章:

java - 我无法在一个 View 中将数据存储在对象中并从另一个 View 访问它(其中包含数据)

java - JTable在arrayList中显示数据

c# - XML版本程序

java.lang.NoClassDefFoundError : Lorg/infinispan/manager/EmbeddedCacheManager

authentication - 如何在 JBoss 中设置用户名和密码

jboss - 制作 server.log append=true

java - hibernate 2.1.6 还是 3.x?

java - 该参数在方法内部如何变化

java - 有人可以插入我朝正确的方向前进吗? Java XML 和结果集

c# xml serialization 自定义 elementName