Collection values overwritten if item elements are not contiguous (mixed content)
See original GitHub issueLooks 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Specificity - CSS: Cascading Style Sheets - MDN Web Docs
Specificity is the algorithm used by browsers to determine the CSS declaration that is the most relevant to an element, which in turn, ......
Read more >How are JavaScript arrays represented in physical memory?
Normally, arrays allocate a contiguous block of memory of fixed length. However, in Javascript, arrays are Object types with special ...
Read more >justify-items - CSS-Tricks
When justify-items is used, it also sets the default justify-self value for all grid items, though this can be overridden at the child...
Read more >Distribute the contents of a cell into adjacent columns
You can divide the contents of a cell and distribute the constituent parts into multiple adjacent cells. For example, if your worksheet contains...
Read more >Fixing mixed content - web.dev
When visiting an HTTPS page in Google Chrome, the browser alerts you to mixed content as errors and warnings in the JavaScript console....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok good. Maybe this helps others to find it too.
This is the way I use to solve the issue. Thank you.