问题
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?
回答1:
You can call serializeNulls() on any JsonAdapter to get a JsonAdapter that'll serialize nulls.
来源:https://stackoverflow.com/questions/51015186/moshi-equivalent-of-gsons-serializenulls