JamesDeCarlo / google-gson

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

Gson 1.4 doesn't support type parameters in superclass. #319

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Sorry, it's resolved in 1.7.1. Please close this issue.

Original comment by x...@99jsj.com on 20 Apr 2011 at 9:31

GoogleCodeExporter commented 9 years ago

Original comment by joel.leitch@gmail.com on 20 Apr 2011 at 3:58