Jackson How to retrieve parent bean in a custom Serializer/Deserializer
If you are using Jackson 2.5, it is possible to access parent object via JsonGenerator.getCurrentValue()
. Or, further up the hierarchy, going via getOutputContext()
(which has getParent()
as well as getCurrentValue()
method).
This is also available through JsonParser
for custom deserializer.
For deserialization, where you don't have access to the JsonGenerator
object. The following worked for me:
JsonStreamContext parsingContext = jsonParser.getParsingContext();
JsonStreamContext parent = parsingContext.getParent();
Object currentValue = parent.getCurrentValue();