1

我们将 RESTEasy 与 jettison 提供程序一起使用(不是 jackson,因为它不支持我们非常喜欢的 Atom 链接)并尝试使用 Swagger 创建有效的 API 文档。但是,jettison 使用“xmlRootElement”生成 json,而 swagger 假定“正常”,类似于杰克逊的 json。因此,生成的文档无效,并且使用 swagger 客户端生成器生成的客户端不起作用。例子:

Java类:


    @Mapped(namespaceMap = @XmlNsMap(jsonName = "atom", namespace =     "http://www.w3.org/2005/Atom"))
    @ApiModel(value = "Service", description = "Service resource representation")
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.NONE)
    public class Service {

    @XmlID
    @XmlAttribute(name = "id")
    @ApiModelProperty(value = "Service's unique id")
    private String id;

    @XmlAttribute(name = "fullName")
    @ApiModelProperty(value = "Service's full name")
    private String fullName;

    @XmlElementRef
    protected RESTServiceDiscovery rest;

    //getters and setters
    ....
    }
   

Swagger 生成的模型:

{  "id": "string",   "fullName": "string"}

来自服务器的响应

{  "service": {  "id": "xyz", "fullName": "Example full name"}}

有什么办法可以让swagger和jettison配合?我们真的不想将提供者更改为杰克逊和丢失的链接。

编辑

由于我们没有找到任何集成上述技术的解决方案,我们决定从 jettison 迁移到 jackson,并自己实现(部分根据我们的需要定制)与 jackson 兼容的 atom 链接的 RESTEasy 规范。我们建议这样的解决方案,因为它很容易,其他抛弃问题会自动解决。

4

0 回答 0