From 193349f4aa7eecf43cc6ebf104e218e704db21d9 Mon Sep 17 00:00:00 2001 From: testcenter Date: Tue, 28 Jun 2016 09:18:03 +0200 Subject: [PATCH] made nullSafe wrapper of JsonAdapter optional --- .../src/main/java/com/google/gson/annotations/JsonAdapter.java | 3 +++ .../internal/bind/JsonAdapterAnnotationTypeAdapterFactory.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gson/src/main/java/com/google/gson/annotations/JsonAdapter.java b/gson/src/main/java/com/google/gson/annotations/JsonAdapter.java index 2ee3e682..a98b27a1 100644 --- a/gson/src/main/java/com/google/gson/annotations/JsonAdapter.java +++ b/gson/src/main/java/com/google/gson/annotations/JsonAdapter.java @@ -94,4 +94,7 @@ public @interface JsonAdapter { /** Either a {@link TypeAdapter} or {@link TypeAdapterFactory}. */ Class value(); + /** false, to be able to handle {@code null} values within the adapter, default value is true. */ + boolean nullSafe() default true; + } diff --git a/gson/src/main/java/com/google/gson/internal/bind/JsonAdapterAnnotationTypeAdapterFactory.java b/gson/src/main/java/com/google/gson/internal/bind/JsonAdapterAnnotationTypeAdapterFactory.java index c079b64d..7cfb910a 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/JsonAdapterAnnotationTypeAdapterFactory.java +++ b/gson/src/main/java/com/google/gson/internal/bind/JsonAdapterAnnotationTypeAdapterFactory.java @@ -73,7 +73,7 @@ public final class JsonAdapterAnnotationTypeAdapterFactory implements TypeAdapte + "JsonSerializer or JsonDeserializer reference."); } - if (typeAdapter != null) { + if (typeAdapter != null && annotation.nullSafe()) { typeAdapter = typeAdapter.nullSafe(); }