假设我们有以下类型:
interface Animal {}
class Dog implements Animal {...}
class Cat implements Animal {...}
class Zoo {
private String animalType;
private Animal animal;
...
}
有了它Cat
并Dog
具有不同的属性,我们如何根据始终存在于 json 中Zoo
的字符串将对象反序列化为适当的 Animal 子类型?animalType
我知道如何做到这一点,custom deserialization
但我找不到使用Jackson annotations
. 如果animalType
财产位于,Cat
或者Dog
但在我的情况下,它的位置在Zoo
.
任何的想法 ?