Using GSON to parse and list objects

I found this article: http://www.dev-articles.com/article/Google-gson-and-list-of-objects-386003

It looks like he is trying to do what I want, which parses my json and puts them in a list of objects.

What I am not getting, or maybe the article is missing something like using the Project class. It seems to come from nowhere.

EDIT:

Thanks yorkw I now have:

public static String parseJSONResponse(String jsonResponse) { Type listType = new TypeToken<List<SingleEvent>>(){}.getType(); List<SingleEvent> events = (List<SingleEvent>) Gson.fromJson(jsonResponse, listType); } 

However, im gets red flags over the type. "Type cannot be allowed for type"

+7
source share
1 answer

A project is a domain model that must be implemented to deserialize a json string:

 Type listType = new TypeToken<List<Project>>(){}.getType(); List<Project> projects = (List<Project>) gson.fromJson(response, listType); 

You can use the generic List type, as described in this article, in Eclipse you get a yellow warning sign "List is a raw type. References to the generic List type must be parameterized."

+11
source

All Articles