jaxb2简化了插件元素而不是简化 [英] jaxb2 simplify plugin elements not simplified

查看:103
本文介绍了jaxb2简化了插件元素而不是简化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用mave-jaxb2插件将XSD转换为JAXB类,并使用jaxb2-basics简化插件。

I have tried to convert XSD to JAXB classes using mave-jaxb2 plugin and jaxb2-basics simplify plugin.

pom.xml中的配置可在此< a href =https://stackoverflow.com/questions/34676734/jaxb2-maven-plugin-in-eclipse-shows-error>发布

The configuration in pom.xml is available in this post

sample.xsd(复杂选择类型)

<xs:complexType name="doclist">
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="document1" type="type1">
                    <xs:annotation>
                        <xs:appinfo>
                            <simplify:as-reference-property/>
                        </xs:appinfo>
                    </xs:annotation>
                </xs:element>
                <xs:element name="document2" type="type2">
                </xs:element>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="heading" type="xs:string" />
    </xs:complexType> 

但是,生成的JAXB类具有aOrB引用。

However the generated JAXB classes have aOrB references.

   @XmlElements({
        @XmlElement(name = "document1", type = Type1.class),
        @XmlElement(name = "document2", type = Type2.class)
    })
    protected List<Object> document1OrDocument2;


推荐答案

你有一个元素属性,因此您必须将注释放在 xs:choice 上,而不是 xs:element 。请参阅文档

You have an elements property so you have to place your annotation on the xs:choice, not on the xs:element. Please see the documentation.

您最有可能想要使用< simplify:as-element-property />

这篇关于jaxb2简化了插件元素而不是简化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆