-
-
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
Nested @JsonUnwrapped
property names not correctly handled
#2461
Comments
That sounds wrong. Thank you for reporting the problem. |
Yes, I can reproduce that. Gnarly... |
@JsonUnwrapped
property names not correctly handled (caching?)
Trying to figure this out: not sure if this is specifically related to caching, but is definitely due to something in logic that handles contextualization related to fetching serializer. |
Ok. I give up, for now. I suspect this is due to multiple levels of nesting, and contextualization being applied by one level, but not across multiple levels. So at this point I would recommend not attempting unwrapping to be used for nesting more than one level. |
Thanks for looking. We do have a workaround that seems to function correctly. We use the object mapper effectively as a singleton and we have found that if we ensure that the equivalent object to BaseContainerContainer is always serialised first then we no longer get the error when serialising either of the two objects. So we initialise our object mappers on application startup using an example object instance. |
@plovell Glad to hear you have a work-around. I hope I can eventually figure this out -- I was really hoping to find a solution in time for 2.10.0, but that is not happening. But there is now a test, and at least it is not (I think!) something specific about mapper-wide caching: it may well be due to per-property serializer caching but that would be more local to solve. One other thing I was thinking but forgot to write down is that specifying
for property might help, as it would allow eager fetching of serializer(s). But I did not test this so have no idea if it can make things work correctly. |
Is there any solution for that? |
There is no solution to this problem at this point. You may have to refactor handling to eliminate a level, or flatten object structure (you can use "multi-level" naming like |
Thank you for your response. from:
to:
What would you recommend? |
@caiquebispoferreira No, not really. Perhaps you could extend |
@JooHyukKim Here's an old and tricky problem -- there's a (failing) unit test for reproducing. Just in case you wanted to find yet more things to work on :) (was reminded of this as the issue was reported on Kotlin module) |
Just sharing things in case it might help anybody. So ordering does matter. My observation is that caching issue happens at UnwrappingBeanPropertyWriter.java#L224. Disabling it makes While my analysis on
These thoughts are just draft, open for guides or collaboration 😆 |
@JsonUnwrapped
property names not correctly handled (caching?)@JsonUnwrapped
property names not correctly handled
We are using @JsonUnwrapped to serialise objects with three levels of nesting. If we serialise the top level object first, then we get the JSON we expect, but if we serialise the second level object first and then try to serialise the top level object, it is as if the @JsonUnwrapped annotation is ignored for the top level object. We are using Jackson databind version 2.9.9.3.
The following test case demonstrates the problem:
The text was updated successfully, but these errors were encountered: