简体   繁体   中英

jackson deserialize wrapped array

I got the following JSON that im trying to deserialize:

{
"items": [
    {
        "id": 29000012,
        "name": "Crystal League I",
        "iconUrls": {
            "small": "https://api-assets.clashofclans.com/leagues/72/kSfTyNNVSvogX3dMvpFUTt72VW74w6vEsEFuuOV4osQ.png",
            "tiny": "https://api-assets.clashofclans.com/leagues/36/kSfTyNNVSvogX3dMvpFUTt72VW74w6vEsEFuuOV4osQ.png",
            "medium": "https://api-assets.clashofclans.com/leagues/288/kSfTyNNVSvogX3dMvpFUTt72VW74w6vEsEFuuOV4osQ.png"
        }
    },
    {
        "id": 29000015,
        "name": "Master League I",
        "iconUrls": {
            "small": "https://api-assets.clashofclans.com/leagues/72/olUfFb1wscIH8hqECAdWbdB6jPm9R8zzEyHIzyBgRXc.png",
            "tiny": "https://api-assets.clashofclans.com/leagues/36/olUfFb1wscIH8hqECAdWbdB6jPm9R8zzEyHIzyBgRXc.png",
            "medium": "https://api-assets.clashofclans.com/leagues/288/olUfFb1wscIH8hqECAdWbdB6jPm9R8zzEyHIzyBgRXc.png"
        }
    }
],
"paging": {
    "cursors": {}
}}

Im trying to deserialize it with the following DTO:

@JsonRootName("items")
@JsonIgnoreProperties(value={ "paging" })
public class League {
    private Long id;
    private String name;
    private IconUrls iconUrls;


    public League() {
    } 
}

class IconUrls {
    private String small;
    private String tiny;
    private String medium;


    public IconUrls() {
    }  
}

But im getting the following error:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name ('items') does not match expected ('List') for type `java.util.List<gg.stats.wrapper.entities.League>

I have also set: DeserializationFeature.UNWRAP_ROOT_VALUE

This is the call of the method from my Client:

List<League> getLeagueList();

The problem might be the "paging" key. Any workaround for that?

I actually found a solution by myself:

@JsonIgnoreProperties(value={ "paging" }, allowGetters=true)
public class ResponseWrapper<T> {

private List<T> items;

@JsonProperty("items")
public List<T> getResponseContent() {
    return this.items;
}

@JsonProperty("items")
public void setResponseContent(List<T> items) {
    this.items = items;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM