I ran today into a problem, try to parse a list of objects coming from a JSON string with a single method avoiding iteration and conversion of individual items of the array. So… after reviewing the doc I found this.

Gson parser = new Gson();
Type listType = new TypeToken<List<Person>>(){}.getType();
List<Person> persons = parser.fromJson(jsonString, listType);

Follow me at @rasensio

Categories: java

Rodrigo Asensio

Apasionado por la tecnología

Leave a Reply

Your email address will not be published. Required fields are marked *