jul
unread,Jul 7, 2010, 10:12:49 AM7/7/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-gson
Hi,
I'd like to deserialize a json object in an ArrayList of Restaurant
objects, as follows:
***
ArrayList<Restaurant> restaurantList;
Type listType = new TypeToken<ArrayList<Restaurant>>()
{}.getType();
restaurantList = gson.fromJson( r, listType );
***
but I get a "java.lang.ClassCastException: java.util.LinkedList"
error.
This works when I define a temp LinkedList and copy it to my
ArrayList, as follows:
***
ArrayList<Restaurant> restaurantList;
LinkedList<Restaurant> tmp;
Type listType = new TypeToken<List<Restaurant>>()
{}.getType();
tmp = gson.fromJson( r, listType );
restaurantList = new ArrayList<Restaurant>(tmp);
***
Is that normal? Is fromJson supposed to return only LinkedList?
Thanks
Jul