Let the runtime throw on circular references
This commit is contained in:
parent
46e65a77c5
commit
4d0775ce8e
@ -38,3 +38,11 @@ GSON 1.x supports type adapters for primitive types
|
||||
GSON 2.x doesn't
|
||||
com.google.gson.functional.CustomTypeAdaptersTest.testCustomSerializerForLong
|
||||
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
|
@ -52,8 +52,7 @@ public class CircularReferenceTest extends TestCase {
|
||||
try {
|
||||
gson.toJson(a);
|
||||
fail("Circular types should not get printed!");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertTrue(expected.getMessage().contains("children"));
|
||||
} catch (StackOverflowError expected) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +63,8 @@ public class CircularReferenceTest extends TestCase {
|
||||
try {
|
||||
gson.toJson(objA);
|
||||
fail("Circular reference to self can not be serialized!");
|
||||
} catch (IllegalStateException expected) { }
|
||||
} catch (StackOverflowError expected) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testSelfReferenceArrayFieldSerialization() throws Exception {
|
||||
@ -74,8 +74,7 @@ public class CircularReferenceTest extends TestCase {
|
||||
try {
|
||||
gson.toJson(objA);
|
||||
fail("Circular reference to self can not be serialized!");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertTrue(expected.getMessage().contains("children"));
|
||||
} catch (StackOverflowError expected) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,8 +93,7 @@ public class CircularReferenceTest extends TestCase {
|
||||
try {
|
||||
gson.toJson(obj);
|
||||
fail("Circular reference to self can not be serialized!");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertTrue(expected.getMessage().contains("Offending"));
|
||||
} catch (StackOverflowError expected) {
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user