I have a custom JsonSerializer
and in the serialize()
method I want to use the default serializer behavior of a registered ObjectMapper
:
class Serializer extends JsonSerializer<MyEntity> {
private ObjectMapper myObjectMapper;
@Override
public void serialize(MyEntity value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
// after processing some logic
myObjectMapper.getSerializerProviderInstance().defaultSerializeValue(value, gen);
}
}
The code above works fine. now I want to do a similar thing but for UnwrappingSerializer
, I mean I want to delegate the unwrappingSerializer to the registered ObjectMapper
something like this:
class UnwrappingSerializer extends JsonSerializer<MyEntity> {
private ObjectMapper myObjectMapper;
@Override
public boolean isUnwrappingSerializer() {
return true;
}
@Override
public void serialize(MyEntity value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
// after processing some logic
myObjectMapper.getDefaultUnwrappingSerializer().serialize(value); // how to do such a thing???
}
}
I'm not sure if Jackson supports such a thing or not. I know another option would be extending UnwrappingBeanSerializer
, that's also fine, the only important thing for me is that I want to delegate the unwrapping serialization to an ObjectMapper and I don't want to do it manually. is there any way to do this?