I have a simple return class that either takes an exception or one of our business objects. If the REST web service method throws an exception, it catches it and sets the exception in the response. If not, it sets the return value in the response and serializes it.
In my case, I'm getting an InvocationTargetError that wraps one of our service exceptions. I set this on my exception on my return class and get the following stack trace:
java.lang.StackOverflowError
com.google.gson.reflect.TypeToken.hashCode(TypeToken.java:280)
java.util.HashMap.get(HashMap.java:300)
java.util.Collections$SynchronizedMap.get(Collections.java:1975)
com.google.gson.Gson.getAdapter(Gson.java:337)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:55)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
and so on...
Anyone have any ideas? This looks like a bug in Gson 2.2.2.
Gson can't handle circular references in the serialized data. Chances are you have one. Fix that and you've fixed your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With