question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Collection values overwritten if item elements are not contiguous (mixed content)

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Oct 23, 2019

Ok good. Maybe this helps others to find it too.

0reactions
vchimishukcommented, Oct 23, 2019

This is the way I use to solve the issue. Thank you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found