[ACCEPTED]-Jackson How to retrieve parent bean in a custom Serializer/Deserializer-jackson
If you are using Jackson 2.5, it is possible 4 to access parent object via JsonGenerator.getCurrentValue()
. Or, further 3 up the hierarchy, going via getOutputContext()
(which has 2 getParent()
as well as getCurrentValue()
method).
This is also available 1 through JsonParser
for custom deserializer.
For deserialization, where you don't have 2 access to the JsonGenerator
object. The following worked 1 for me:
JsonStreamContext parsingContext = jsonParser.getParsingContext();
JsonStreamContext parent = parsingContext.getParent();
Object currentValue = parent.getCurrentValue();
Note: getCurrentValue will be null if you 5 are using custom serialization
I worked around 4 this by setting the parent object into the 3 child's serializer instance and then accessing 2 it when the child's serializer was called 1 by jackson.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.