FasterXML / jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Apache License 2.0
567 stars 221 forks source link

If array property contents are split across separate elements, earlier values are overwritten #251

Open sohibegit opened 7 years ago

sohibegit commented 7 years ago
File file = new File("data.xml");
XmlMapper xmlMapper = new XmlMapper();
List<MyClass> value = Arrays.asList(xmlMapper.readValue(file, MyClass[].class));

value.size(); output cannot exceed 100 no matter how many in the xml file it's like there is limit that i dont know of or it's a but Using: Linux Mint 18.2 Spring Boot 1.5.4.RELEASE Jackson 2.8.8 and i tried almost all of them still the same

cowtowncoder commented 7 years ago

There is no such limitation to size explicitly imposed by Jackson. But it is always possible that some bug somewhere could result in incorrect handling. So I think I would need full reproduction, including contents of data.xml, as well as definition of MyClass.

sohibegit commented 7 years ago

Maybe it is not an issue, but I found the cause, it is because data.xml contains <?xml tag after every 100 records It's like multiple xml files merged into 1 file So the xmlMapper runs until he sees the <?xml and stops I dont have control on creating this combined xml file that's why i had to hack it and removed the extra tags.

cowtowncoder commented 7 years ago

@sohibegit if you have test case or sample input, that would help.

Processing instructions (ones starting with <?) should not be problematic in themselves; they should be skipped. But perhaps something in handling is not doing that.

However: XML specification DOES NOT allow use of xml as processing instruction identifier: it is illegal to embed these at any place except for beginning of document, with no leading whitespace. All compliant parsers are expected to throw exception if such are found (at least by default; some may allow accepting non-conforming input). You can check this by using Xerces or Woodstox directly as parser. So there is also possibility of exception being thrown but caught by something in processing -- sometimes code swallows exceptions leading to hard to diagnose problems like this one.

sohibegit commented 6 years ago

notes.xml

<?xml version="1.0" ?>
<notes>
    <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
    </note>
    <note>
        <to>any</to>
        <from>any</from>
        <heading>Reminder</heading>
        <body>Don't forget</body>
    </note>
</notes>
<?xml version="1.0" ?>
<notes>
    <note>
        <to>Bob</to>
        <from>Tove</from>
        <heading>Reminder</heading>
        <body>Party!</body>
    </note>
</notes>

When I used an XML file similar to this for object mapping I get the first 2 notes only without getting the rest of notes and it didn't throw an exception to tell me what's wrong

cowtowncoder commented 6 years ago

@sohibegit that is not legal XML file, if it tries to include multiple XML declarations, for one. Surprising if parser does not report this via exception.

But aside from that, second list property value will override earlier value. Same would occur with properties of any other type.

sohibegit commented 6 years ago

It would be better if Jackson throw an exception in this case.

cowtowncoder commented 6 years ago

In former case, parser really should do that, but for latter it would be nice if it would be considered an error case. Currently this is unfortunately not possible since there is not tracking for values being set. But I will re-phrase issue title so that this can be considered an improvement idea.