I have a type from a third party library (JSONB
from jooq) that I've written a custom serializer/deserializer for:
@JsonComponent
public class JSONBSerializer extends JsonSerializer<JSONB> {
@Override
public void serialize(JSONB jsonb, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(jsonb.toString());
}
}
@JsonComponent
public class JSONBDeserializer extends JsonDeserializer<JSONB> {
@Override
public JSONB deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return JSONB.valueOf(jsonParser.getValueAsString());
}
}
I am wondering if there is a way to tell spring or jackson to use these by default without having to annotate every JSONB field in the project with @JsonSerialize(using = JSONBSerializer.class)
and @JsonDeserialize(using = JSONBDeserializer.class)
?