Skip to content
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

ObjectReader.readValue(JsonNode) does not work correctly with polymorphic types, value to update #1831

Closed
basmastr opened this issue Nov 17, 2017 · 4 comments
Milestone

Comments

@basmastr
Copy link

basmastr commented Nov 17, 2017

There seems to be a difference in behavior of ObjectReader::readValue(JsonNode) and ObjectReader::readValue(String). In particular I've found a difference in how they treat the combination of @JsonUnwrapped and @JsonSubTypes and a custom deserializer. I am attaching two minimal test cases. They are identical but one uses ObjectReader::readValue(JsonNode) (and fails) and the other one uses ObjectReader::readValue(String) and passes.
Tested on version 2.9.2.

unwrappedSubtypesBug.zip

@cowtowncoder
Copy link
Member

I hope to have time to look into this. One thing to keep in mind is that Tree Model is meant to be exact representation of the content, without transformations, and is explicitly different than POJOs.
So more like "untyped" structure of Lists and Maps, for which unwrapping is not applied (unwrapping requires existence of properties, concept that is POJO-specific, not applicable to Maps or ObjcetNodes).
Similarly polymorphic handling isn't really applicable either, with minor exceptions (like POJO property declared as Object should be able to handle JsonNode values if polymorphic handling is enabled).

@cowtowncoder
Copy link
Member

Ok. This is interesting... usage seems correct. And using jsonNode.traverse(mapper) instead of jsonNode works. So something does seem wrong here.

@cowtowncoder
Copy link
Member

Ok. So the problem is not so much use of String or JsonNode in itself, but rather how JsonNode is traversed: it is passed ObjectCodec, which in this case is ObjectReader.
That is fine in itself but reader is configured with object to update, which causes problems.
I'll need to see if there is a way to easily clear "object to update" for this particular use.

cowtowncoder added a commit that referenced this issue Dec 6, 2017
@cowtowncoder cowtowncoder added this to the 2.9.3 milestone Dec 6, 2017
@cowtowncoder cowtowncoder changed the title ObjectReader::readValue(JsonNode) doesn't seem to work correctly with @JsonUnwrapped and @JsonSubtypes ObjectReader.readValue(JsonNode) doesn't seem to work correctly with polymorphic types, value to update Dec 6, 2017
@cowtowncoder cowtowncoder changed the title ObjectReader.readValue(JsonNode) doesn't seem to work correctly with polymorphic types, value to update ObjectReader.readValue(JsonNode) does not work correctly with polymorphic types, value to update Dec 6, 2017
@cowtowncoder
Copy link
Member

Fixed for 2.9.3 (and was actually already working for `master, 3.0.0-SNAPSHOT).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants