From 4f6a36d68fbc38f9fb4a84a43875e64676a73139 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 9 Sep 2011 03:40:39 +0000 Subject: [PATCH] Support reading nulls into strings --- .../com/google/gson/internal/bind/TypeAdapters.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index 2f503786..bf996f80 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -16,6 +16,10 @@ package com.google.gson.internal.bind; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -24,10 +28,6 @@ import java.util.Locale; import java.util.StringTokenizer; import java.util.UUID; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - /** * Type adapters for basic types. */ @@ -108,6 +108,10 @@ public final class TypeAdapters { public static final TypeAdapter STRING = new TypeAdapter() { public String read(JsonReader reader) throws IOException { + if (reader.peek() == JsonToken.NULL) { + reader.nextNull(); // TODO: does this belong here? + return null; + } return reader.nextString(); } public void write(JsonWriter writer, String value) throws IOException {