What steps will reproduce the problem?
class Foo<T> {
T val;
}
class Bar
extends Foo<Integer> {
}
public class GsonTest {
public static void main(String[] args) {
Bar bar = new Bar();
bar.val = 123;
Gson gson = new Gson();
gson.toJson(bar);
}
}
Got the error:
Exception in thread "main" java.lang.UnsupportedOperationException: Expecting
parameterized type, got class com.bee32.plover.ajax.Bar.
Are you missing the use of TypeToken idiom?
See http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener
at com.google.gson.TypeInfoFactory.getActualType(TypeInfoFactory.java:97)
at com.google.gson.TypeInfoFactory.getTypeInfoForField(TypeInfoFactory.java:54)
at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:148)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:123)
at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:56)
at com.google.gson.Gson.toJsonTree(Gson.java:230)
at com.google.gson.Gson.toJson(Gson.java:315)
at com.google.gson.Gson.toJson(Gson.java:270)
at com.google.gson.Gson.toJson(Gson.java:250)
at com.bee32.plover.ajax.GsonTest.main(GsonTest.java:20)
Original issue reported on code.google.com by x...@99jsj.com on 20 Apr 2011 at 9:26
Original issue reported on code.google.com by
x...@99jsj.com
on 20 Apr 2011 at 9:26