Let the runtime throw on circular references

This commit is contained in:
Jesse Wilson 2011-09-28 19:38:43 +00:00
parent 46e65a77c5
commit 4d0775ce8e
2 changed files with 13 additions and 7 deletions

View File

@ -38,3 +38,11 @@ GSON 1.x supports type adapters for primitive types
GSON 2.x doesn't GSON 2.x doesn't
com.google.gson.functional.CustomTypeAdaptersTest.testCustomSerializerForLong com.google.gson.functional.CustomTypeAdaptersTest.testCustomSerializerForLong
com.google.gson.functional.CustomTypeAdaptersTest.testCustomDeserializerForLong com.google.gson.functional.CustomTypeAdaptersTest.testCustomDeserializerForLong
GSON 1.x throws IllegalStateException on circular references
GSON 2.x lets the runtime throw a StackOverflowError
com.google.gson.functional.CircularReferenceTest.testCircularSerialization
com.google.gson.functional.CircularReferenceTest.testSelfReferenceSerialization
com.google.gson.functional.CircularReferenceTest.testSelfReferenceArrayFieldSerialization
com.google.gson.functional.CircularReferenceTest.testSelfReferenceCustomHandlerSerialization

View File

@ -52,8 +52,7 @@ public class CircularReferenceTest extends TestCase {
try { try {
gson.toJson(a); gson.toJson(a);
fail("Circular types should not get printed!"); fail("Circular types should not get printed!");
} catch (IllegalStateException expected) { } catch (StackOverflowError expected) {
assertTrue(expected.getMessage().contains("children"));
} }
} }
@ -64,7 +63,8 @@ public class CircularReferenceTest extends TestCase {
try { try {
gson.toJson(objA); gson.toJson(objA);
fail("Circular reference to self can not be serialized!"); fail("Circular reference to self can not be serialized!");
} catch (IllegalStateException expected) { } } catch (StackOverflowError expected) {
}
} }
public void testSelfReferenceArrayFieldSerialization() throws Exception { public void testSelfReferenceArrayFieldSerialization() throws Exception {
@ -74,8 +74,7 @@ public class CircularReferenceTest extends TestCase {
try { try {
gson.toJson(objA); gson.toJson(objA);
fail("Circular reference to self can not be serialized!"); fail("Circular reference to self can not be serialized!");
} catch (IllegalStateException expected) { } catch (StackOverflowError expected) {
assertTrue(expected.getMessage().contains("children"));
} }
} }
@ -94,8 +93,7 @@ public class CircularReferenceTest extends TestCase {
try { try {
gson.toJson(obj); gson.toJson(obj);
fail("Circular reference to self can not be serialized!"); fail("Circular reference to self can not be serialized!");
} catch (IllegalStateException expected) { } catch (StackOverflowError expected) {
assertTrue(expected.getMessage().contains("Offending"));
} }
} }