I am trying to deserialize the following XML:
<root>
<foo name="AAA" />
<bar name="BBB" />
<foo name="CCC" />
</root>
My Jackson classes are:
@Data
public class Foo {
@JacksonXmlProperty(isAttribute = true)
private String name;
}
Bar is identical, just a different class name. (In the real code they are different, this is just an example).
And the root class is
@Data
public class Root {
@JacksonXmlProperty(localName = "foo")
@JacksonXmlElementWrapper(useWrapping = false)
private List<Foo> foos;
@JacksonXmlProperty(localName = "bar")
@JacksonXmlElementWrapper(useWrapping = false)
private List<Bar> bars;
}
When I try to deserialize the XML, using this code
System.out.println(new XmlMapper().readValue(theXml, Root.class));
The result is this (note the lack of "AAA"):
Root(foos=[Foo(name=CCC)], bars=[Bar(name=BBB)])
However, if I move the fields in the XML so that both foo
tags are next to each other, it prints
Root(foos=[Foo(name=AAA), Foo(name=CCC)], bars=[Bar(name=BBB)])
I'm using jackson-dataformat-xml 2.11.1 which is the latest.
What is going on here, and how can I fix it?