-
- Notifications
You must be signed in to change notification settings - Fork 233
Open
Labels
mixed-contentIssue related to XML mixed contentIssue related to XML mixed contentwill-not-fixIssue for which there is no plan to fix as described or requestedIssue for which there is no plan to fix as described or requested
Description
Looks like we have a bug in the parser. Parsing next simple document leads to data loss.
<Data> <foo>foo1</foo> <foo>foo2</foo> <bar>bar1</bar> <foo>foo3</foo> <foo>foo4</foo> </Data> Expected result: foo java-property contains list of 4 values.
Actual result: foo java-property contains list of 2.
Setter for foo property is called two times for every tags group: foo1, foo2 and foo3, foo4. Second setter call overrides data gathered by the first call. As result parsing result contains foo list as foo3, foo4 instead of expected foo1, foo2, foo3, foo4.
Here is a java-code to reproduce the issue.
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import java.util.List; @JacksonXmlRootElement(localName = "data") class Data { @JacksonXmlCData @JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty private List<String> foo; @JacksonXmlCData @JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty private List<String> bar; public List<String> getFoo() { return foo; } public void setFoo(List<String> foo) { this.foo = foo; } public List<String> getBar() { return bar; } public void setBar(List<String> bar) { this.bar = bar; } } public class Foo { public static void main(String[] args) throws JsonProcessingException { String xml = "" + "<Data>" + " <foo>foo1</foo>" + " <foo>foo2</foo>" + " <bar>bar1</bar>" + " <foo>foo3</foo>" + " <foo>foo4</foo>" + "</Data>"; XmlMapper m = new XmlMapper(); Data data = m.readValue(xml, Data.class); System.err.println(data.getFoo()); // Expected ["foo1", "foo2", "foo3", "foo4"] but ["foo3", "foo4"] given. } } jackson-dataformat-xml version: 2.10.0
geekarist, valb3r, jimmykane, Juan-EBI, pnovak and 1 more
Metadata
Metadata
Assignees
Labels
mixed-contentIssue related to XML mixed contentIssue related to XML mixed contentwill-not-fixIssue for which there is no plan to fix as described or requestedIssue for which there is no plan to fix as described or requested