Description
(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 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.