I have this JSON model class,
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;
}
When I try to deserialize the following JSON,
{
assets: [
{
"category": "Series",
"id": "ID1",
"seriesName": "SeriesName1",
"seasonNumber": 1
},
{
"category": "Movies",
"id": "ID2",
"movieName": "MovieName1"
}
]
}
I see that all the properties are deserialized properly, except the category
property, which are null
in both asset types.
Am I doing something wrong? Or is this the expected behavior - property that is used to infer subtype is discarded during deserialization?