From 56aa8283505e1813bcd800c3c05dbdacccf22ee7 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Sat, 22 Jan 2011 22:43:43 +0000 Subject: [PATCH] Minor clean-up in Gson class. --- gson/src/main/java/com/google/gson/Gson.java | 25 ++++---------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java index 84ec2d9e..b8032a23 100644 --- a/gson/src/main/java/com/google/gson/Gson.java +++ b/gson/src/main/java/com/google/gson/Gson.java @@ -78,8 +78,6 @@ public final class Gson { //TODO(inder): get rid of all the registerXXX methods and take all such parameters in the // constructor instead. At the minimum, mark those methods private. - private static final String NULL_STRING = "null"; - static final boolean DEFAULT_JSON_NON_EXECUTABLE = false; // Default instances of plug-ins @@ -240,7 +238,7 @@ public final class Gson { */ public String toJson(Object src) { if (src == null) { - return serializeNulls ? NULL_STRING : ""; + return toJson(JsonNull.createJsonNull()); } return toJson(src, src.getClass()); } @@ -281,14 +279,10 @@ public final class Gson { * @since 1.2 */ public void toJson(Object src, Appendable writer) throws JsonIOException { - try { - if (src != null) { - toJson(src, src.getClass(), writer); - } else if (serializeNulls) { - writeOutNullString(writer); - } - } catch (IOException ioe) { - throw new RuntimeException(ioe); + if (src != null) { + toJson(src, src.getClass(), writer); + } else { + toJson(JsonNull.createJsonNull(), writer); } } @@ -561,15 +555,6 @@ public final class Gson { return target; } - /** - * Appends the {@link #NULL_STRING} to the {@code writer} object. - * - * @param writer the object to append the null value to - */ - private void writeOutNullString(Appendable writer) throws IOException { - writer.append(NULL_STRING); - } - @Override public String toString() { StringBuilder sb = new StringBuilder("{")