Merge pull request #863 from nykolaslima/explicit-null-in-json
handle explicit null values in JSON
This commit is contained in:
commit
2360cfa05c
@ -262,8 +262,8 @@ public class ProtoTypeAdapter
|
||||
String jsonFieldName =
|
||||
getCustSerializedName(fieldDescriptor.getOptions(), fieldDescriptor.getName());
|
||||
|
||||
if (jsonObject.has(jsonFieldName)) {
|
||||
JsonElement jsonElement = jsonObject.get(jsonFieldName);
|
||||
JsonElement jsonElement = jsonObject.get(jsonFieldName);
|
||||
if (jsonElement != null && !jsonElement.isJsonNull()) {
|
||||
// Do not reuse jsonFieldName here, it might have a custom value
|
||||
Object fieldValue;
|
||||
if (fieldDescriptor.getType() == ENUM_TYPE) {
|
||||
|
@ -66,4 +66,11 @@ public class ProtosWithPrimitiveTypesTest extends TestCase {
|
||||
assertEquals("foo", proto.getMsg());
|
||||
assertEquals(3, proto.getCount());
|
||||
}
|
||||
|
||||
public void testDeserializeWithExplicitNullValue() {
|
||||
SimpleProto proto = gson.fromJson("{msg:'foo',count:null}", SimpleProto.class);
|
||||
assertEquals("foo", proto.getMsg());
|
||||
assertEquals(0, proto.getCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user