Is it possible to serialize object using Jackson,but ignoring custom serializers registered with annotation @JsonSerialize(using = MyCustomSerializer.class)
?
Rationale:
I want to use Jackson to convert my object to Map, using com.fasterxml.jackson.databind.ObjectMapper.convertValue(object,Map.class)
.
Currently it does not work, because my class has custom serializer (@JsonSerialize) but misses deserializer. I require custom serializer, and I really do not need and do not want to write deserializer.
ObjectMapper.convertValue
uses my serialization then fails at deserialization.
I would like to have ObjectMapper that will just ignore @JsonSerialize and use default serialization logic. Is that possible with Jackson?
That is entirely possible. You could disable annotations on a per ObjectMapper basis, like this:
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.USE_ANNOTATIONS);
For more details check the documentation over at github or check the examples at baeldung.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With