我有Parent
和Child
類。JaxB,Eclipse Moxy,polymorhpic映射
A House
類的字段類型爲Parent
,它可以引用Child
對象。我需要使用Eclipse Moxy將其映射到XML。
其XSD會是這樣的:
<xs:complexType name="Parent" abstract="true"> ...other fields...
<xs:complexType name="Child" > <xs:extension base="Parent"> ...other fields...
<xs:element name="child" type="Child" substitutionGroup="parent" /> <xs:element name="parent" type="Parent" abstract="true" />
<xs:complexType name="House"> <xs:element ref="parent"/>
衆議院類包含一個JAXBElement的指向家長: @XmlElementRef(name = "parent", namespace = "abc", type = JAXBElement.class) protected JAXBElement<? extends Parent> parent;
如何通過House.oxm.xml文件映射House
類,以便此多態映射能夠正確工作?
<java-type name="House" xml-accessor-type="NONE"> <java-attributes> <xml-element-ref java-attribute="?????????"/>
我試圖映射使用「@」,但它不工作 - 它只是將對象添加到XML的參考字符串(@Parent)。