3
각 코드 행을 살펴 보았지만 Jackson의 처리 방법을 생각합니다. 내부 다형성.Jackson의 @JsonTypeInfo (use = Id.CUSTOM, include = As.PROPERTY, property = "type")는 "type"을 제외한 JSON의 모든 필드를 읽습니다.
Animal
을 확장 Dog
및 Cat
의 고전적인 예를 사용 :
@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입니다 그 exte nds AbstractTypeIdResolver
. 매우 이상한 이유로
bark_decibel
및
meow_level
은 JSON에서 직렬화되어 있지만,
type
는
null
로지고 있습니다. 어떤 아이디어?