If I have a POJO field of type A
that I want serialized as being of type B
, I can easily achieve this with a pair of Converter
s:
@JsonSerialize(converter=ConvA2B.class)
@JsonDeserialize(converter=ConvB2A.class)
private A field;
But what if I want all the fields of that type in all the POJOs to be treated like that? Is there a global converters configuration?
To provide a bit of context, I'm trying to serialize java.time.LocalDateTime
fields as unix timestamps and one possible solution I found is to convert each field to java.time.Instant
with a custom type converter such as:
public static class Conv extends StdConverter<LocalDateTime, Instant> {
@Override
public Instant convert(LocalDateTime value) {
return value.toInstant(ZoneOffset.UTC);
}
}