-
-
Notifications
You must be signed in to change notification settings - Fork 229
Incorrectly parsing XML with duplicated tag names #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Correct, this problem does result from impedance between XML and JSON. But Map is pretty specific type, so I wonder if it might be possible to add bit more interaction to make it work. |
I am not sure there is generic solution to this problem: your solution assumes that we can use heuristic to combine sub-trees, but this would not be guaranteed for all kinds of structures. But it could work for some subset of cases; so question then is whether to try to work on something that would work with the standard Map deserializer (which is not format specific), or to add XML-specific Map deserializer. As to XML: there is the immediate problem wherein value of duplicate property may well be something other than another Map; so it is not clear what would be the proper way to merge things. For example:
would not quite work, as value for entry "r" would be String "A". So what should be done for the following entry? |
I think the answer here is "works as designed" -- 'untyped' binding to Maps and Lists will not be working correctly without assuming more advanced rules, and I don't want to move to that direction. |
For people who stumble upon this issue, see the Gist provided in #205 for a work around. |
Trying to parse the following XML document:
with:
new XmlMapper().readValue(xml, Map.class)
ignores the first "r" (r -> {a -> A}) node, overriding it with a second one (r -> {b -> B, c -> C}). It should generate a map with a single key and array value instead: r -> [{a -> A}, {b -> B, c -> C}]. The problem is here (last line of org.codehaus.jackson.map.deser.MapDeserializer#_readAndBind):
Although this can be worked around by using special map implementation instead of Map.class, but if the duplicated tags appear deeper in XML document (not at top level), there is no easy workaround, see org.codehaus.jackson.map.deser.UntypedObjectDeserializer#mapObject class (LinkedHashMap creation).
Of course the root cause of this problem is the assumption that there are no duplicate properties in JSON. In XML such nodes should be treated as arrays.
The text was updated successfully, but these errors were encountered: