Cannot deserialize instance of `pojo.SuperRoot` out of START_ARRAY token

28 Views Asked by At

Restassured is unable to deserialise the JSON response into my POJO classes (this could be related to link.

My Super root class

public class SuperRoot {
    private List<Root> root; //includes getters & setters
}
public class Root { //includes getters & setters
    public List<Object> breeds;
    public String id;
    public String url;
    public int width;
    public int height;
    public List<Category> categories;
}

My JSON which is supposed to be deserialised looks like below:

[
    {
        "breeds": [
            
        ],
        "id": "1jm",
        "url": "https://cdn2.thecatapi.com/images/1jm.jpg",
        "width": 401,
        "height": 600
    },
    {
        "breeds": [
            
        ],
        "id": "75q",
        "url": "https://cdn2.thecatapi.com/images/75q.jpg",
        "width": 500,
        "height": 333
    },
    {
        "breeds": [
            
        ],
        "id": "86o",
        "url": "https://cdn2.thecatapi.com/images/86o.jpg",
        "width": 500,
        "height": 344
    }
]

deserialisation should be successful since Root class will have a list of smaller JSONs

Github project link https://github.com/apoorvSinha/catProject

1

There are 1 best solutions below

0
apoorv sinha On

It was resolved when I used TypeReference like below

List<Root> cat =new ObjectMapper().readValue(response.asString(), new TypeReference<List<Root>>(){});
        for(Root st: cat) {
            System.out.println(st.getHeight());
}