### Question:
JsonAdapter { @CheckReturnValue public final JsonAdapter<T> nullSafe() { if (this instanceof NullSafeJsonAdapter) { return this; } return new NullSafeJsonAdapter<>(this); }  @CheckReturnValue abstract @Nullable T fromJson(JsonReader reader); @CheckReturnValue final @Nullable T fromJson(BufferedSource source); @CheckReturnValue final @Nullable T fromJson(String string); abstract void toJson(JsonWriter writer, @Nullable T value); final void toJson(BufferedSink sink, @Nullable T value); @CheckReturnValue final String toJson(@Nullable T value); @CheckReturnValue final @Nullable Object toJsonValue(@Nullable T value); @CheckReturnValue final @Nullable T fromJsonValue(@Nullable Object value); @CheckReturnValue final JsonAdapter<T> serializeNulls(); @CheckReturnValue final JsonAdapter<T> nullSafe(); @CheckReturnValue final JsonAdapter<T> nonNull(); @CheckReturnValue final JsonAdapter<T> lenient(); @CheckReturnValue final JsonAdapter<T> failOnUnknown(); @CheckReturnValue JsonAdapter<T> indent(final String indent);  }### Answer:
@Test public void nullSafe() throws Exception { JsonAdapter<String> toUpperCase = new JsonAdapter<String>() { @Override public String fromJson(JsonReader reader) throws IOException { return reader.nextString().toUpperCase(Locale.US); } @Override public void toJson(JsonWriter writer, String value) throws IOException { writer.value(value.toUpperCase(Locale.US)); } }.nullSafe(); JsonReader reader = factory.newReader("[\"a\", null, \"c\"]"); reader.beginArray(); assertThat(toUpperCase.fromJson(reader)).isEqualTo("A"); assertThat(toUpperCase.fromJson(reader)).isNull(); assertThat(toUpperCase.fromJson(reader)).isEqualTo("C"); reader.endArray(); JsonWriter writer = factory.newWriter(); writer.beginArray(); toUpperCase.toJson(writer, "a"); toUpperCase.toJson(writer, null); toUpperCase.toJson(writer, "c"); writer.endArray(); assertThat(factory.json()).isEqualTo("[\"A\",null,\"C\"]"); }
@Test public void nullSafeDoesntDuplicate() { JsonAdapter<Boolean> adapter = new Moshi.Builder().build().adapter(Boolean.class).nullSafe(); assertThat(adapter.nullSafe()).isSameInstanceAs(adapter); }