开发者

JAXB Does not Marshall as Expected

开发者 https://www.devze.com 2023-03-25 21:07 出处:网络
A buddy of mine asked me to post this question: EDIT: He decided to post the question on his own here: JAXB Unmarshalls XML IncorrectlyI tried to delete this question but couldn\'t.

A buddy of mine asked me to post this question:

EDIT: He decided to post the question on his own here: JAXB Unmarshalls XML Incorrectly I tried to delete this question but couldn't.

I am trying to marshall a java class, called MyContainer. This class extends my another class, called Container. Container has a variable called: protected List<ResourceReference<Component>> child

The only variable MyContainer has is the one it inherits from Container. This List, however, will not marshall with JAXB when I have child listed as an XmlList.

It will marshall as an XmlElement, however this is not how I want the data displayed. When it is marshalled as an XmlElement, it lists the attributes in the List, but not 'heirarchially' It just lists the two elements as if they were properties of the class, as opposed to belonging to the child list.

How do I get Jaxb to marshall the List (Which is instantiated as an ArrayList) correctly?

EDIT: Here's an example: This is what I am getting:

<MyContainer name="Container Name">
    <booleanVal>false</booleanVal>
    <child id="Test Comp 1"/>
    <child id="Test Comp 2"/>
</and>开发者_如何学C;

This is more what I expect:

<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>

Admittly, my current results is probably from the List in Container being marked with the @XmlElement annotation. However, JAXB will not marshall anything else..


Annotate your list with @XmlElementWrapper. See javadoc.

0

精彩评论

暂无评论...
验证码 换一张
取 消