From 1dcdd3fb3f139d9fad3df072104af3110cb31733 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Thu, 1 Oct 2009 22:15:53 +0000 Subject: [PATCH] Implemented suggestions from code review r432 by adding a JsonNull for primitives if the value is null. --- .../main/java/com/google/gson/JsonSerializationVisitor.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java index 73c04587..ed26a383 100644 --- a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java @@ -135,10 +135,8 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor { } public void visitPrimitive(Object obj) { - if (obj != null) { - JsonElement json = new JsonPrimitive(obj); - assignToRoot(json); - } + JsonElement json = obj == null ? JsonNull.createJsonNull() : new JsonPrimitive(obj); + assignToRoot(json); } private void addAsChildOfObject(Field f, Type fieldType, Object fieldValue) {