4

I recently replaced Moshi for Gson in a backend that's expected to serialize responses with nullable values as { "value": null }, instead of {}.

Neither Moshi nor Gson do this by default, but Gson has an option to do it directly in the builder:

Gson gson = new GsonBuilder().serializeNulls().create().

Does Moshi have support for something similar?

Luiz Scheidegger
  • 788
  • 5
  • 12

1 Answers1

8

You can call serializeNulls() on any JsonAdapter to get a JsonAdapter that'll serialize nulls.

Jesse Wilson
  • 39,078
  • 8
  • 121
  • 128