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
Original issue reported on code.google.com by
nicholas...@gmail.com
on 2 Feb 2012 at 3:14