I have a basic ObjectMapper
configured with a custom serializer and deserializer for a property in my Object. I would like to capture the latency for serialization and deserialization of my entire Object using a Micrometer Timer
meter.
I can add a custom serializer and deserializer at the top Object level, instead of just the property that I have it for, and pass in the Timer
to capture metrics. But, this would entail parsing the entire Object explicitly for the sole purpose of capturing metrics. I am hoping to get feedback on whether this is the only option or if there is a better way to achieve this.
The Object I am working with
public class Person {
String name;
int age;
Address address
}
The property I have custom serializer and deserializer for
public class Address {
String addLineOne;
String addLineTwo;
int zipCode;
}
ObjectMapper
configured
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(Deserialization.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule module = new SimpleModule();
module.addDeserializer(Address.class, new AddressDeserializer());
module.addSerializer(Address.class, new AddressSerializer());
objectMapper.registerModule(module);
return objectMapper;
}