I can't see to properly annotate my classes such that a self-closed tag causes the class to create an empty list. In order words, the list isn't specified in the XML at all.
For my question I'll refer to the following two example classes:
@XmlRootElement(name="a")
public class A {
@XmlElement
List<B> bs;
}
@XmlRootElement(name="b")
public class B {
@XmlValue
String v;
}
This XML unmarshals fine:
<a>
<b>One</b>
<b>Two</b>
<b>Three</b>
</a>
This second XML example also unmarshals correctly with the intended empty list:
<a>
<b/>
</a>
However, the third example causes the XML to not unmarshal at all.
<a/>
The behavior I'd like to see when unmarshaling the third example is identical to the second where the class gets initialized with an empty list. Is this possible using JAXB, or am I trying to do something that flies in the face of the defined behavior?
No comments:
Post a Comment