Jackson多态类型数据的反序列化
json串中要有property中指明的字段,如@class,才可以解析成功public class Zoo { public Animal animal; } @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") @JsonSubTypes({ @JsonSubTypes.Type(value = Dog.class, name = "Dog"), @JsonSubTypes.Type(value = Cat.class, name = "Cat")}) static class Animal { // All animals have names, for our demo purposes... public String name; protected Animal() { } } static class Dog extends Animal { public double barkVolume; // in decibels public Dog() { } } static class Cat extends Animal { boolean likesCream; public int lives; public Cat() { } }
补充:web前端 , JavaScript ,