Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我最近在一个后端替换了 Gson 的 Moshi,该后端预计将具有可空值的响应序列化为{ "value": null },而不是{}.
{ "value": null }
{}
默认情况下,Moshi 和 Gson 都不执行此操作,但 Gson 可以选择直接在构建器中执行此操作:
Gson gson = new GsonBuilder().serializeNulls().create().
Gson gson = new GsonBuilder().serializeNulls().create()
Moshi 是否支持类似的东西?
您可以在任何 JsonAdapter 上调用 serializeNulls() 以获取将序列化空值的 JsonAdapter。