Moshi equivalent of Gson's “serializeNulls”

浪尽此生 提交于 2020-01-30 08:20:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!