I have a number of objects with a set of common properties in a superclass:
public Superclass { int id; String name; ... }
And I have subclasses that inherit from the superclass, but each one needs its own fully described @JsonCreator
public Subclass1 extends Superclass { String color; @JsonCreator public Subclass1(@JsonProperty("id") int id, @JsonProperty("name") String name, @JsonProperty("color") String color) { super(id, name); this.color = color; } } public Subclass2 extends Superclass { int height; @JsonCreator public Subclass1(@JsonProperty("id") int id, @JsonProperty("name") String name, @JsonProperty("height") int height) { super(id, name); this.height = height; } }
Is there a way for Jackson (2.x) to extract information from the superclass regarding the expected JSON fields and avoid this repetition?
source share