asolfre / google-gson

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

LinkedTreeMap cannot be cast to #550

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.run the code
2.
3.

What is the expected output? What do you see instead?
print every user in the list,but shows "LinkedTreeMap cannot be cast to 
com.he.common.User"

What version of the product are you using? On what operating system?
2.2.4 win7

Please provide any additional information below.

Original issue reported on code.google.com by hechangg...@yeah.net on 17 Dec 2013 at 9:20

Attachments:

GoogleCodeExporter commented 9 years ago
If you change your Type 
from -- Type typeOfHashMap=new 
TypeToken<Map<String,List<Object>>>(){}.getType(); 
to -- Type typeOfHashMap=new TypeToken<Map<String,List<User>>>(){}.getType();
the deserialization is successful. I believe your original code is incorrectly 
using the Type class. If you have to set up a custom Type, you should be as 
specific as possible.

Original comment by jack.roy...@gmail.com on 1 May 2014 at 11:10

GoogleCodeExporter commented 9 years ago
Do what #1 said and it will fix your issue. If no type information is available 
Gson will deserialize into a Map as the exception clearly outlines.

Original comment by j...@squareup.com on 9 Aug 2014 at 5:48