Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android jackson json object mapper array deserialization

i need help parsing a response with the jackson mapper to a POJO. i have this as a response:

 "data": [{
        "item": {
            "downloaded": false,
            "moderated": false,
            "add": false
        }
    },
    {
        "item": {
            "downloaded": false,
            "moderated": false,
            "add": false }
// more

so how do i bind this one with the mapper to a POJO? here is my class that i am trying but it returns that "item" is not recognized and not allowed to be ignored.

public ArrayList<Item> data =  new ArrayList<Item>();

where item is a public static class Item with constructors and all the fields above with getters and setters.

how do i do this. i cant seem to find anywhere how to read data from an array this way.

like image 752
DArkO Avatar asked Feb 17 '11 01:02

DArkO


1 Answers

JsonNode jsonNode = mapper.readValue(s, JsonNode.class); 
JsonNode userCards = jsonNode.path("data");
List<Item> list = mapper.readValue(userCards.toString(), new TypeReference<List<Item>>(){});
like image 52
maziar Avatar answered Sep 30 '22 19:09

maziar