Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to ignore @JsonSerialize annotation?

Tags:

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?

like image 500
Bartosz Bilicki Avatar asked Apr 18 '16 20:04

Bartosz Bilicki


1 Answers

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.

like image 158
ingenious Avatar answered Sep 28 '22 03:09

ingenious