Deserializing JSON list into list of objects with Flexjson

vikke picture vikke · Aug 13, 2012 · Viewed 7k times · Source

I'm trying to deserialize the following json:

{ "books": [ {"id":"1","name":"book 1"}, {"id":"2","name":"book 2"} ] }

Into a List. It worked before with this json:

[ {"id":"1","name":"book 1"}, {"id":"2","name":"book 2"} ] }

Using this code:

List<Book> items = new JSONDeserializer<ArrayList<Book>>()
.use("values", Book.class).deserialize(json, ArrayList.class);

But now after looking at multiple examples I am at a loss, is it possible to deserialize directly into a list?

Answer

Alfredo Carrillo picture Alfredo Carrillo · Mar 29, 2013

Taking the sample from @vikke I successfully applied the deserialization of a list of longs.

List<Long> idsLong = new JSONDeserializer<List<Long>>().use("values", Long.class).deserialize("[123,456,789]");