diff --git a/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java index 79ddb246..f600a49f 100644 --- a/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java @@ -195,4 +195,29 @@ public class CustomTypeAdaptersTest extends TestCase { return context.serialize(src, typeOfSrc); } } + + public void testCustomDeserializerForLong() { + final ClassWithBooleanField customDeserializerInvoked = new ClassWithBooleanField(); + customDeserializerInvoked.value = false; + Gson gson = new GsonBuilder().registerTypeAdapter(Long.class, new JsonDeserializer() { + public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + customDeserializerInvoked.value = true; + String str = json.getAsJsonPrimitive().getAsString(); + return str.length() == 0 ? null : Long.parseLong(str); + } + }).create(); + String json = "{'value':null}"; + ClassWithWrapperLongField target = gson.fromJson(json, ClassWithWrapperLongField.class); + assertNull(target.value); + assertTrue(customDeserializerInvoked.value); + } + + private static class ClassWithWrapperLongField { + Long value; + } + + private static class ClassWithBooleanField { + Boolean value; + } }