I have a number of objects with a set of shared properties in a superclass:
public Superclass {
int id;
String name;
...
}
And I have subclasses which inherit from the superclass but each of them need their 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 any way for Jackson (2.x) to pull information from the superclass regarding expected JSON fields and to avoid this repetition?