Can Jackson polymorphic deserialization be used to serialize to a subtype if a specific field is present?
As of Jackson 2.12.2, the following accomplishes the goal using the “deduction-based polymorphism” feature. If properties distinct to the Bird subtype (i.e. wingspan) are present, the deserialized type will be Bird; else it will be Animal: @JsonTypeInfo(use=Id.DEDUCTION, defaultImpl = Animal.class) @JsonSubTypes({@Type(Bird.class)}) public class Animal { public String name; public int age; } Deduction-based polymorphism The …