让我们看Jackson控制多态的注解:
- @JsonTypeInfo – indicates details of what type information to include in serialization 指出序列化包含的类型信息细节
- @JsonSubTypes – indicates sub-types of the annotated type 指出被注解类型的子类
- @JsonTypeName – defines a logical type name to use for annotated class 定义被注解类使用的逻辑名称
让我们看使用这三个注解的例子--序列化/反序列化Zoo实体:
public class Zoo { public Animal animal; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value