diff --git a/gson/GSON 2.0 NOTES.txt b/gson/GSON 2.0 NOTES.txt index 82a216a0..3e53fc40 100644 --- a/gson/GSON 2.0 NOTES.txt +++ b/gson/GSON 2.0 NOTES.txt @@ -53,3 +53,9 @@ GSON 1.x sometimes sets subclass fields when an InstanceCreator returns a subcla the top level object or a collection element. GSON 2.x sets fields of the requested type only com.google.gson.functional.InstanceCreatorTest.testInstanceCreatorReturnsSubTypeForField + +GSON 1.x applies different rules for versioning for classes vs fields. So, if you deserialize a + JSON into a field that is supposed to be skipped, the field is set to null (or default value). + However, if you deserialize it to a top-level class, a default instance is returned. +GSON 2.x returns null for the top-level class. +com.google.gson.functional.VersioningTest.testIgnoreLaterVersionClassDeserialization \ No newline at end of file diff --git a/gson/src/test/java/com/google/gson/functional/VersioningTest.java b/gson/src/test/java/com/google/gson/functional/VersioningTest.java index 7838555c..90c1debb 100644 --- a/gson/src/test/java/com/google/gson/functional/VersioningTest.java +++ b/gson/src/test/java/com/google/gson/functional/VersioningTest.java @@ -88,13 +88,10 @@ public class VersioningTest extends TestCase { public void testIgnoreLaterVersionClassDeserialization() { Gson gson = builder.setVersion(1.0).create(); String json = "{\"a\":3,\"b\":4,\"c\":5,\"d\":6}"; - Version1_2 version1_2 = gson.fromJson(json, Version1_2.class); - // Since the class is versioned to be after 1.0, all fields should get set to - // their default values. - assertEquals(A, version1_2.a); - assertEquals(B, version1_2.b); - assertEquals(C, version1_2.c); - assertEquals(D, version1_2.d); + Version1_2 version1_2 = gson.fromJson(json, Version1_2.class); + // Since the class is versioned to be after 1.0, we expect null + // This is the new behavior in Gson 2.0 + assertNull(version1_2); } public void testVersionedGsonWithUnversionedClassesSerialization() {