abdulrehmanz / google-gson

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

gson not working when converting list<Class> where class contains JsonObject #487

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create an Item class with getters and setters.
public class Item { private JsonObject param; }

2. Create a string representation of a json and call it itemList
String itemList = "[{param:{color: 1,shape:1}, {param:{color: 2,shape:2}]";

3. Use gson to convert the itemList into a List<Item>
List<Item> list = gson.fromJson(itemList, new 
TypeToken<List<Item>>(){}.getType());

What is the expected output? What do you see instead?

Loop through the list and print out param. It will show {}.
I'm expecting to see 
{ color: 1, shape: 1}
{ color: 2, shape: 2}

What version of the product are you using? On what operating system?
Im running gson 2.2.2 on windows 7.

Please provide any additional information below.

To get around this problem, I'm currently using a Map in place of a JsonObject.

Original issue reported on code.google.com by ThaiTra...@gmail.com on 12 Nov 2012 at 1:55

GoogleCodeExporter commented 9 years ago
The current behavior is correct. Why should we treat JsonObject as a map?

Original comment by inder123 on 12 Nov 2014 at 11:42