android jackson json object mapper array deserialization android jackson json object mapper array deserialization json json

android jackson json object mapper array deserialization


JsonNode jsonNode = mapper.readValue(s, JsonNode.class); JsonNode userCards = jsonNode.path("data");List<Item> list = mapper.readValue(userCards.toString(), new TypeReference<List<Item>>(){});


Your example is missing couple of pieces (esp. definition of Item), to know if your structure is compatible; but in general JSON and Object structures need to match. So, you would at least need something like:

public class DataWrapper {  public List<Item> data; // or if you prefer, setters+getters}

and if so, you would bind with:

DataWrapper wrapper = mapper.readValue(json, DataWrapper.class);

and access data as

List<Item> items = wrapper.data;


Here's my variant of maziar's code.

List<Item> list = mapper.readValue( s, new TypeReference<List<Item>>(){} );

It just eliminates the converting first to a JsonNode and converts instead directly to a List; still works fine, outputting a list of Items.