我的一个朋友要我发这个问题:
编辑:他决定自己在这里发布问题:JAXB Unmarshalls XML Incorrectly我试图删除这个问题,但不能。
我正在尝试编组一个名为MyContainer
的java类。这个类扩展了我的另一个类,名为Container
。 Container
有一个名为protected List<ResourceReference<Component>> child
唯一的变量MyContainer
具有从Container
继承的变量。但是,当我将孩子列为List
时,此XmlList
将不会与JAXB编组。
它将作为XmlElement
编组,但这不是我想要显示数据的方式。当它被编组为XmlElement
时,它会列出List
中的属性,但不会列出'heirrchially'它只列出这两个元素,就好像它们是类的属性一样,而不是属于孩子名单。
如何让Jaxb正确编组List
(实例化为ArrayList)?
编辑:这是一个例子: 这就是我得到的:
<MyContainer name="Container Name">
<booleanVal>false</booleanVal>
<child id="Test Comp 1"/>
<child id="Test Comp 2"/>
</and>
这更符合我的期望:
<MyContainer name="Container Name">
<booleanVal>false</booleanVal>
<child> /// This would be the class variable of the extended Class, Container
<ResourceRef id="Entry 1">
<ResourceRef id="Entry 2">
</child>
</and>
当然,我当前的结果可能是来自容器中的List被标记为@XmlElement注释。但是,JAXB不会编组任何其他内容..