From 4b8fd66c9dd50dd4c848b7ba40a549fbbcc69c7f Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Fri, 16 Dec 2011 17:21:31 +0000 Subject: [PATCH] Added a test for issue 389 --- .../google/gson/functional/NullObjectAndFieldTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java b/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java index 04f55d67..9b29daba 100755 --- a/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java +++ b/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java @@ -149,11 +149,19 @@ public class NullObjectAndFieldTest extends TestCase { assertEquals("[\"1\",null,\"3\"]", result); } + // test for issue 389 + public void testAbsentJsonElementsAreSetToNull() { + Gson gson = new Gson(); + ClassWithMembers target = gson.fromJson("{array:[1,2,3]}", ClassWithMembers.class); + assertTrue(target.array.length == 3 && target.array[1] == 2); + assertNull(target.str); + assertNull(target.col); + } + private static class ClassWithNullWrappedPrimitive { private Long value; } - @SuppressWarnings("unused") private static class ClassWithMembers { String str; int[] array;