I have custom JsonSerializer:
new JsonSerializer<T>() {
@Override
public void serialize(T instance, JsonGenerator gen, SerializerProvider sp) throws IOException, JsonProcessingException
{
try {
instance = someFunction(instance);
SerializableString serializableString = new SerializedString(defaultMapper.writeValueAsString(instance));
gen.writeRawValue(serializableString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
For my pourpuses, i need a way to pass gen.getOutputContext()
to the defaultMapper.writeValueAsString(instance)
. Is there a way to achieve this? Or am I using the ObjectMapper the wrong way? Thank you for any insight.
EDIT: the defaultMapper
is of type ObjectMapper
.