我有这个 JSON 模型类,
public class Response {
@JsonTypeInfo(use= JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="category")
@JsonSubTypes({
@Type(value = Series.class, name = "Series"),
@Type(value = Movies.class, name = "Movies")})
public static abstract class Asset {
public String category;
public String id;
}
public static class Series extends Asset {
public String seriesName;
public int seasonNumber;
}
public static class Movies extends Asset {
public String movieName;
}
public Asset[] assets;
}
当我尝试反序列化以下 JSON 时,
{
assets: [
{
"category": "Series",
"id": "ID1",
"seriesName": "SeriesName1",
"seasonNumber": 1
},
{
"category": "Movies",
"id": "ID2",
"movieName": "MovieName1"
}
]
}
我看到所有属性都已正确反序列化,但category
属性除外,它们都null
属于两种资产类型。
难道我做错了什么?或者这是预期的行为 - 用于推断子类型的属性在反序列化期间被丢弃?