jackson-dataformat-xml
jackson-dataformat-xml copied to clipboard
If array property contents are split across separate elements, earlier values are overwritten
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
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
.
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.
@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.
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
@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.
It would be better if Jackson throw an exception in this case.
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.