You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if this applies also for deserializing a json message, but by using the XmlMapper the resulting Map does only contain the last child node in case there are some `maxOccurence="unbounded" elements.
The reason seems to be that the Vanilla implementation just uses result.put(key,value) instead of checking if there already exists an entry.
I was able to get the expected result by modifying the method mapObject(JsonParser jp, DeserializationContext ctxt) and replacing all 'result.put' with an addValue delegate which looks like this:
private void addValue(Map<String, Object> result, String fieldName, Object value) {
if (!result.containsKey(fieldName)) {
result.put(fieldName, value);
} else {
Object existing = result.get(fieldName);
if (existing instanceof List) {
((List) existing).add(value);
} else {
List list = new ArrayList();
list.add(existing);
list.add(value);
result.put(fieldName, list);
}
}
}
I could provide a pull request if this is considered a bug/improvement and is desired, but for that i would need to know where to hook in, as the current solution is based on the databinding deserializer.
The text was updated successfully, but these errors were encountered:
Note: similar to planned work for JsonNode with XML improvements: FasterXML/jackson-databind#2732 -- will tag with 2.12 to possibly address this in similar way, as suggested.
Just realized that there is #205 that is same thing (I think) -- and although usually I'd close newer issue as dup, there is bit more discussion on that one so will close this issue instead.
(Moved from databinding as requested)
I don't know if this applies also for deserializing a json message, but by using the
XmlMapper
the resulting Map does only contain the last child node in case there are some `maxOccurence="unbounded" elements.The reason seems to be that the
Vanilla
implementation just usesresult.put(key,value)
instead of checking if there already exists an entry.I was able to get the expected result by modifying the method
mapObject(JsonParser jp, DeserializationContext ctxt)
and replacing all 'result.put' with anaddValue
delegate which looks like this:I could provide a pull request if this is considered a bug/improvement and is desired, but for that i would need to know where to hook in, as the current solution is based on the databinding deserializer.
The text was updated successfully, but these errors were encountered: