コードの各行をステップ実行しましたが、Jackson が内部的にポリモーフィズムを処理する方法だと思います。
Dog
およびCat
拡張の古典的な例を使用しAnimal
ます。
@JsonTypeInfo(use = Id.CUSTOM, include = As.PROPERTY, property = "type")
@JsonTypeIdResolver(AnimalTypeIdResolver.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class Animal implements Serializable {
public AnnotatorBundleConfig(String name) {
super();
this.name = name;
}
犬のクラス :
public class DogAnimal extends Animal {
@JsonCreator
public DogAnimal(
@JsonProperty(value="name", required=true) String name,
@JsonProperty(value="bark_decibel") int bark_decibel)
{
super(name);
this.bark_decibel = bark_decibel;}
猫クラス:
public class CatAnimal extends Animal {
@JsonCreator
public CatAnimal(
@JsonProperty(value="name", required=true) String name,
@JsonProperty(value="meow_level") int meow_level)
{
super(name);
this.meow_level = meow_level;}
はAnimalTypeIdResolver
、 を拡張する典型的な TypeIdResolver ですAbstractTypeIdResolver
。
非常に奇妙な理由で、bark_decibel
とmeow_level
は JSON から逆シリアル化されていますがtype
、null
. 何か案は?