I have a list setter on a class that’s annotated with both @XmlElementWrapper(name = “foos”) and @XmlElement(name = “foo”).
When I unmarshall XML that has no <foos></foos> or <foo/> elements, the setter is called and passed an empty list. Is there a way to get the following?:
- When there is no <foos/>, do not call the setter. Or if the setter must be called, pass null.
- When <foos/> is present but empty, pass an empty list to the setter.
- When <foos> has one or more child <foo/> elements, pass a populated list.
You could use an XmlAdapter for this use case:
input1.xml
input2.xml
input3.xml
Root
Child
ChildAdapter
Demo
Output