Skip to content

UntypedObjectDeserializer.Vanilla not handling xml sequences (same tags) correctly #152

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

Closed
Antibrumm opened this issue May 21, 2015 · 2 comments
Labels
duplicate Issue is duplicate of another issue

Comments

@Antibrumm
Copy link

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

@cowtowncoder
Copy link
Member

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.

@cowtowncoder cowtowncoder added 2.12 and removed 2.12 labels May 20, 2020
@cowtowncoder
Copy link
Member

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.

@cowtowncoder cowtowncoder added the duplicate Issue is duplicate of another issue label May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issue is duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants