使用jaxb / maven更改元素的类型

时间:2016-06-21 13:40:05

标签: jaxb jaxb2 maven-jaxb2-plugin

我正在尝试使用XJB从XSD生成java类。我在0.13.1版本中运行maven插件maven-jaxb2-plugin。 我想用其他类型替换元素类型。

以下是我的xsd文件的摘录:

<xs:complexType name="TestType">
    <xs:sequence>
        <xs:element name="field1" type="xs:date" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="Test2Type">
    <xs:sequence>
        <xs:element name="field2" type="xs:string" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

如果我想将field1xs:date更改为其他内容我没有错误。

以下是我的xjb对此修改的摘录:

<bindings node="./xs:complexType[@name='TestType']/xs:sequence/xs:element">
            <property>
                <baseType>
                    <javaType name="com.test.WTKTest" parseMethod="com.test.WTKTest.parse" printMethod="com.test.WTKTest.print"/>
                </baseType>
            </property>
</bindings>

现在如果我替换

<xs:element name="field1" type="xs:date" minOccurs="1" maxOccurs="1"/>

通过

<xs:element name="field1" type="TestType2" minOccurs="1" maxOccurs="1"/>

我相应地更改了parseprint方法,我收到了此错误:

compiler was unable to honor this javaType customization. It is attached to a wrong place, or its inconsistent with other bindings.

我已经完成了一些测试,如果初始类型是xs命名空间的类型,我可以更改元素的类型,否则它会失败!

感谢您的帮助!

0 个答案:

没有答案