-
-
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
ObjectMapper convertValue does not check if the value is already of target type #4661
Comments
Have a look at method definition ( jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java Line 4541 in 5e0deda
Issue for change in 2.10 was this: |
Oh sry I didn't see that but thanks for pointing that out. However I am wondering what is really meant by "let caller handle optimizations if ones are desired" (from #2220)? |
Instead of |
sure the "first" level is not a problem, but what if the object is deeper down in the hierarchy? |
I don't think it's feasible at a deeper level. convertValue works by serializing and then deserializing. During serialization, the serializer has no knowledge of what type a particular property will eventually be deserialized to. So I don't see a generic approach happening. If you have some contextual information you could eg create a serializer that uses writeEmbeddedObject instead of actually serializing a particular type. |
Okay thanks for the info, I will look into a more specific solution that fits my use case. |
Why does
objectMapper.convertValue
not check if the object already has the desired target type and then return the object immediatly.jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Line 4602 in 5e0deda
When converting a class which has a recursive getter of some form, I expect to get the object back immediatly if it has the correct type to begin with.
Instead I get:
Infinite recursion (StackOverflowError) (through reference chain:....
The text was updated successfully, but these errors were encountered: