Added tests for Issue 68

This commit is contained in:
Inderjeet Singh 2008-10-30 01:45:44 +00:00
parent c98d7bc340
commit 3f53e8b223

View File

@ -82,6 +82,30 @@ public class NullObjectAndFieldTest extends TestCase {
assertTrue(json.contains("\"array\":null"));
}
/**
* Added to verify http://code.google.com/p/google-gson/issues/detail?id=68
*/
public void testNullWrappedPrimitiveMemberSerialization() {
Gson gson = gsonBuilder.serializeNulls().create();
ClassWithNullWrappedPrimitive target = new ClassWithNullWrappedPrimitive();
String json = gson.toJson(target);
assertTrue(json.contains("\"value\":null"));
}
/**
* Added to verify http://code.google.com/p/google-gson/issues/detail?id=68
*/
public void testNullWrappedPrimitiveMemberDeserialization() {
Gson gson = gsonBuilder.create();
String json = "{'value':null}";
ClassWithNullWrappedPrimitive target = gson.fromJson(json, ClassWithNullWrappedPrimitive.class);
assertNull(target.value);
}
private static class ClassWithNullWrappedPrimitive {
private Long value;
}
public void testExplicitSerializationOfNullCollectionMembers() {
Gson gson = gsonBuilder.create();
ClassWithMembers target = new ClassWithMembers();
@ -119,5 +143,4 @@ public class NullObjectAndFieldTest extends TestCase {
return obj;
}
}
}