0

I've created a ticket here that explains the issue I am experiencing https://bugs.eclipse.org/bugs/show_bug.cgi?id=460541

Essentially if we have an @XmlElementWrapper with @XmlElements then when unmarshalling if XML element is empty the setter on the JAXB object is never called to set an empty collection. This works with JAXB RI.

Example method and annotation definition:

@XmlElementWrapper(nillable=true)
@XmlElements(value = {@XmlElement(name="subelement", type=SubElement.class), @XmlElement(name="subsubelemenet", type=SubTypeOfSubElement.class)})
public List<SubElement> getSubElementCollectionWithSubType() {
    return subElementCollectionWithSubType;
}

I would be very happy to hear any workaround if there is one other than removing the @XmlElements all together.

1 Answers1

0

JAXB does not use setters on lists, it normally calls get and appends to the list, so your getter should created a list if it was null.

Zielu
  • 8,312
  • 4
  • 28
  • 41
  • That would be strange behaviour. According to this marshalling example, empty collections and null collections are marshalled to XML correctly so I would assume unmarshalling works in the same way: http://blog.bdoughan.com/2012/12/jaxb-representing-null-and-empty.html. – Brendan Dobbs Mar 01 '15 at 22:17
  • well, it is based on my own experience, I had custom setters for list that had side effects and after one of the jaxb udpate, they stopped being called as jaxb was using only getters to append to collections. See http://stackoverflow.com/questions/13913000/why-doesnt-jaxb-generate-setters-for-lists or http://stackoverflow.com/questions/14986562/how-does-unmarshalling-work-in-jaxb – Zielu Mar 01 '15 at 22:43