I want to know if the below code is violating open closed principle.
Animal
is a parent class of Dog
, however Animal
has jackson annotations that help ObjectMapper
(de)serialize the classes. Anyone who extends Animal
will have to edit only annotations present on Animal
to make sure (de)serialization works as intended leaving the class untouched.
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
// all subclasses
@Type(value = Dog.class, name = "dog")
})
public abstract class Animal {
// fields, constructors, getters and setters
}
public class Dog extends Animal {
}
Aucun commentaire:
Enregistrer un commentaire