Jaxb 将Choice与Any组合在一起将无法封送而不使用@XmlRootElement

Jaxb 将Choice与Any组合在一起将无法封送而不使用@XmlRootElement,jaxb,Jaxb,我使用JAX-B从预定义的XSD生成POJO。 我遇到了这个元素定义 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns="http://order.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://order.example.com" elementFormDefault="qual

我使用JAX-B从预定义的XSD生成POJO。 我遇到了这个元素定义

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://order.example.com"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://order.example.com"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:element name="Order">
        <xs:complexType>
            <xs:sequence>
                <xs:choice maxOccurs="unbounded">
                    <xs:choice minOccurs="0" maxOccurs="3">
                        <xs:element name="Credit" type="CreditType" form="qualified"/>
                        <xs:element name="GiftCard" type="GiftCardType" form="qualified"/>
                    </xs:choice>
                    <xs:any namespace="##other" processContents="lax"/>
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="CreditType">
        <xs:sequence>
            <xs:element name="Number" type="xs:string" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="GiftCardType">
        <xs:sequence>
            <xs:element name="Code" type="xs:long" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>
我得到以下错误:

[com.sun.istack.internal.SAXException2: unable to marshal type "com.example.order.CreditType" as an element because it is missing an @XmlRootElement annotation]
这可以通过添加一个强制XJC对类进行注释的绑定来解决,问题是在我的例子中,这个问题出现过很多次,因此必须为每种类型添加一个绑定并不能很好地扩展

有人有更好的建议吗

我上传了一个maven项目,再现了这个问题: 只需运行:

git clone https://github.com/jcfandino/jaxb-choice.git && cd jaxb-choice
mvn test
[com.sun.istack.internal.SAXException2: unable to marshal type "com.example.order.CreditType" as an element because it is missing an @XmlRootElement annotation]
git clone https://github.com/jcfandino/jaxb-choice.git && cd jaxb-choice
mvn test