Jackson XML appears not to be able to marshal a XML having a tag with a certain attribute whose name is also being used for the nested children tags (“occ”, in the following case).
<root> <txt occ="1"> <occ id="1">first element</occ> <occ id="2">second element</occ> </txt> <txt occ="2"> <occ id="1">first element</occ> <occ id="2">second element</occ> </txt> </root>
Changing the name of the XmlAttribute “occ” or of the XmlElement “occ” makes it work.
This is how I’ve annotated my Txt Class:
@XmlAccessorType(XmlAccessType.FIELD) public class Txt { @XmlAttribute(name="occ") private String occ_attr; @XmlElement(name="occ") private List<Occ> occ = new ArrayList<Occ>(); //getters and setters not annotated
And this is how I’ve annotated the Occ class:
public class Occ { @XmlAttribute private String id; @XmlValue private String value; //getters and setters not annotated
Advertisement
Answer
Apparently it’s an issue of the library. As of today, the issue hasn’t been solved yet:
https://github.com/FasterXML/jackson-dataformat-xml/issues/65