-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
readTree explodes when reading json with type information #88
Comments
Will have a look. Trees and polymorphic types are somewhat incompatible (trees expose physical JSON structure; and type information is metadata that is hidden when dealing with POJOs), but exception is probably not the right thing to do regardless. |
Well, as someone who's not familiar with Jackson's inner workings, I don't see any incompatibility. IMO JsonNode should simply treat the type info property as just another property. If that's doable, it would be great. |
Yes, when reading JSON with type info, it should be exposed as-is, not handled. But there are other cases where things are less clear; specifically when a POJO property would have type of |
Ok, I add these as failing unit tests; fix will need to wait until 2.1 is released this week. In the meantime, it is safe to say that "default typing" will not work well with conversion between trees and JSON Values, for same reason as default typing (or type info embedding) will not work with plain "convertValue()". |
I'd prefer it if the tree model will just treat the type property as another node in the tree. This way, transforming from serialized form to tree will work and then transforming from tree to an object graph will also work. |
Agreed, but the problem is that ObjectMapper treats So I have to think about proper way to deal with this. Conceptually I fully agree in that it'd be best to just expose physical JSON Tree details, including type information. One work around for now is to use two ObjectMappers, and instead of 'convertValue' (or its variants, 'valueToTree' and 'treeToValue' which are just convenience wrappers) do conversions explicitly by serializing using one, deserialize using the other. |
Any news regarding this issue? We have exactly the same problem. |
No news. I can have a look at tests to see if I can think of anything new here. |
@bostjanl Can you elaborate on what is your specific usage, and which Jackson version you are using? |
Using the latest released version - 2.3.1. |
Ok. Are you using |
Added unit tests (failing) for this -- have an idea of how this should be handled. Basically, if root type is |
I think there are two ways to tackle this; in both cases need to prevent use of type info for
Both should work, need to think of which one would be preferable. |
That was fast :-) |
Ok good. Sometimes problem is not as difficult to fix as I initially fear. :) |
As an added bonus, I suspect #353 got fixed due to this as well; tests pass for 2.4 (master). |
When reading json that has type information, readTree explodes on ClassCastException upon trying to assert that JsonNode is a supertype of the type in the type information. This is, of course, wrong.
As far as I can tell, the bug is in AsPropertyTypeDeserializer.deserializeTypedFromObject:
Follows is a test that recreates the bug:
The text was updated successfully, but these errors were encountered: