'Jackson disable typing for typed annotated classes

Let's say I have the following classes:

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "class")
@JsonSubTypes({ @JsonSubTypes.Type(value = Rabbit.class) })
abstract class Animal {
}

class Rabbit {
}

When serializing I usually need the type, hence the annotations. I have a use case where I would like to serialize but without the type property. I don't want to make use of DTOs. I can't modify the annotations.

I tried to find an option in the ObjectMapper class to overwrite these annotations, but without success.

ObjectMapper serializer = new ObjectMapper();
serializer.deactivateDefaultTyping();

Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source