Quarkus Panache 实体上的 JAXB 注释导致 REST 调用失败

JAXB annotations on a Quarkus Panache entity causes REST call to fail

我已将 class 注释为 Panache 实体。但是,我还包含了 JAXB 注释:

@Entity
@XmlRootElement(name = "Person")
@XmlAccessorType(XmlAccessType.NONE)
public class Person extends PanacheEntity {

    @XmlAttribute(name = "Name")
    public String name;
}

当我尝试 return 来自 REST 调用的对象时,出现以下异常:

2019-12-08 08:30:01,917 ERROR [org.jbo.res.res.i18n] (vert.x-worker-thread-3) RESTEASY002005: Failed executing GET /person: org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
model.Person#name has mutually exclusive annotations @javax.xml.bind.annotation.XmlTransient and @javax.xml.bind.annotation.XmlAttribute
    this problem is related to the following location:
        at @javax.xml.bind.annotation.XmlTransient()
        at model.Person
    this problem is related to the following location:
        at @javax.xml.bind.annotation.XmlAttribute(namespace="##default", name="Name", required=false)
        at model.Person

    at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:187)
    at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:149)

所以 Quarkus Panache 框架似乎正在将 @XmlTransient 添加到我的 public 属性。

我可以通过将名称 属性 的访问权限更改为私有并包括 getters/setters 来解决这个问题。但是,这种方法失去了 Panache 的一个好处,即您的代码更加紧凑和可读。

是否可以保留 class 属性 的 public 访问器并使其与 JAXB 一起工作?

有趣的用例。

我认为在自动添加 @XmlTransient 之前,我们需要检查属性是否没有任何冲突的 JAXB 注释。

这可能也是 JSON-B/Jackson 的问题,因为我们做同样的事情。

我没有看到任何明显的解决方法:我们需要在 Quarkus 中修复它。

你能用一个简单的复制器打开一个 GitHub 问题吗?谢谢!