abhijeetjais20 / google-gson

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

Gson 1.7.1 - Gson.toJson(myObject) causes StackOverflowError on com.google.gson.ParameterizedTypeHandlerMap.getHandlerFor(ParameterizedTypeHandlerMap.java:143) #405

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When calling the following code from a Tomcat servlet:

Gson myjson = new Gson();
String json = myjson.toJson(myObject);
myjsons.add(json);

We get a stack overflow error: 

java.lang.StackOverflowError
        com.google.gson.ParameterizedTypeHandlerMap.getHandlerFor(ParameterizedTypeHandlerMap.java:141)
        .....
        .....
        com.google.gson.ParameterizedTypeHandlerMap.getHandlerFor(ParameterizedTypeHandlerMap.java:143)
        com.google.gson.ParameterizedTypeHandlerMap.getHandlerFor(ParameterizedTypeHandlerMap.java:143)
        com.google.gson.ObjectTypePair.getMatchingHandler(ObjectTypePair.java:66)
        com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:176)
        com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(JsonSerializationVisitor.java:160)
        com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:101)
        com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:62)
        com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:53)
        com.google.gson.Gson.toJsonTree(Gson.java:220)
        com.google.gson.Gson.toJson(Gson.java:260)
        com.google.gson.Gson.toJson(Gson.java:240)

myObject is an instance of: 

public class MyObject
{
public String a;
   public String b;
   public String c;
   public String d;
   public String e;
   public String f;
   public String g;
   public String h;
   public String i;
   public String j;

   public void init()
   {
     this.a= "";
     this.b= "";
     this.c= "";
     this.d= "";
     this.e= "";
     this.f= "";
     this.g= "";
     this.h= "";
     this.i= "";
     this.j= "";
   }
}

Here is the weird part... it seems to be related to Tomcat redeploys. If we 
redeploy tomcat and try again, sometimes (randomly) the stack overflow no 
longer occurs and it will continue to work until the next redeploy. 

Why would redeploying Tomcat have an affect on the Gson library? 

Original issue reported on code.google.com by nicholas...@gmail.com on 2 Feb 2012 at 3:14

GoogleCodeExporter commented 9 years ago
Upgrading to latest version seemed to eliminate the error (not sure why). 

Original comment by nicholas...@gmail.com on 2 Feb 2012 at 10:35

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 3 Feb 2012 at 2:42