Jackson's polymorphic type processing - property dropped

I have a 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 next JSON,

{
    assets: [
        {
            "category": "Series",
            "id": "ID1",
            "seriesName": "SeriesName1",
            "seasonNumber": 1
        },
        {
            "category": "Movies",
            "id": "ID2",
            "movieName": "MovieName1"
        }
    ]
}

I see that all properties are deserialized properly, with the exception of properties categorythat are nullin both types of resources.

Am I doing something wrong? Or is this expected behavior — a property that is used to output the subtype discarded during deserialization?

+5
source share
2 answers

, , . , , 6, post.

+2

visible = true:

@JsonTypeInfo(
    use= JsonTypeInfo.Id.NAME,
    include=JsonTypeInfo.As.PROPERTY,
    property="category",
    visible = true
)
+18

All Articles