1
假设我们有以下几种类型:杰克逊多态性反序列化使用注释
interface Animal {}
class Dog implements Animal {...}
class Cat implements Animal {...}
class Zoo {
private String animalType;
private Animal animal;
...
}
有了这样的Cat
和Dog
有不同的特性,我们怎么可以反序列化Zoo
对象基于animalType
串合适的动物亚型总是存在于json?我知道如何做到这一点custom deserialization
,但我找不到使用Jackson annotations
做同样的事情。如果animalType
属性位于Cat
或Dog
,但在我的情况下,它的位置在Zoo
。
有什么想法?
谢谢JsonTypeInfo.As.EXTERNAL_PROPERTY正是我一直在寻找。 –