【问题标题】:Including swagger api cause conflicts in jaxb provider under JBoss EAP在 JBoss EAP 下的 jaxb provider 中包含 swagger api 会导致冲突
【发布时间】:2016-09-29 15:54:10
【问题描述】:

我使用 JBoss 6.x EAP 和 RestEasy。

当我尝试在我的 Web 应用程序中包含 swagger.io 1.5.0 并尝试使用外部 jersey rest 客户端进行调用时,我注意到它给了我错误,因为由于忽略了 @ json 转换期间的 XMLElement(name="some_value")。

这可能是因为 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 提供程序进行对象映射的任何建议?

【问题讨论】:

    标签: java xml jboss jaxb swagger


    【解决方案1】:

    最终使用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>
    

    【讨论】:

      猜你喜欢
      • 2014-02-28
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 2019-11-02
      • 2021-06-20
      • 1970-01-01
      • 2011-06-27
      • 2020-08-13
      相关资源
      最近更新 更多