jerryhui633 / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

object list in Gson #394

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. I want to add list of object in gson. Example there is list of person object 
that list need to add in gosn to get String object for response.
Code
List<Person> personList = new ArrayList<Perosn>();
personList.add(new Person());
personList.add(new Person());
personList.add(new Person());

Gson gson = new Gson();
String personObject = gson.toJson(personList);

I am getting error while doing this.

I am using gson-2.0.jar and related jar for that.

Operating system is windows 7.

Original issue reported on code.google.com by aijaz....@gmail.com on 28 Dec 2011 at 1:01

GoogleCodeExporter commented 9 years ago
You'll need the two-argument version of toJson(). The 2nd argument should be 
this: 
  new TypeToken<List<Person>>() {}.getType()

For ease in triage, you should include a stacktrace when you report a bug like 
this.

Original comment by limpbizkit on 29 Dec 2011 at 5:29