List<Object> l = new ArrayList<Object>();
l.add("abc");
String s = (String) l.get(0); /////// No Exception here
System.out.println(l);
String json = gson.toJson(l);
System.out.println(json);
Type t = new TypeToken<List<Object>>() {
}.getType();
List<Object> dl = gson.fromJson(json, t);
String ds = (String) dl.get(0); /////Class Cast Exception here
Doing something like the above one. I am trying to serialize a list of Objects. First element in that is a String, but when I deserialized the list and reading the first element to a string it's throwing a classcastexception. And there are no exceptions when reading the first element to a string before serializing.
What's the reason behind this?
Object, that did not come from JSON. (Unless GSON usesObjectas a "null" value or some such -- I'm not up on all the various JSON kits and their quirks.) Again, where is the JSON?