Moshi: Rfc3339DateJsonAdapter fails covert to json Date NULL values.

Created on 9 Jun 2017  路  2Comments  路  Source: square/moshi

Date adapter fails to convert object with null Date field values instead of just writing null value to json.

java.lang.NullPointerException at java.util.Calendar.setTime(Calendar.java:1770) at com.squareup.moshi.Iso8601Utils.format(Iso8601Utils.java:46) at com.squareup.moshi.Rfc3339DateJsonAdapter.toJson(Rfc3339DateJsonAdapter.java:32) at com.squareup.moshi.Rfc3339DateJsonAdapter.toJson(Rfc3339DateJsonAdapter.java:25) at com.squareup.moshi.ClassJsonAdapter$FieldBinding.write(ClassJsonAdapter.java:212) at com.squareup.moshi.ClassJsonAdapter.toJson(ClassJsonAdapter.java:181) at com.squareup.moshi.JsonAdapter$2.toJson(JsonAdapter.java:135) at com.squareup.moshi.JsonAdapter.toJson(JsonAdapter.java:46) at com.squareup.moshi.JsonAdapter.toJson(JsonAdapter.java:52)

UPDATE: null value from json payload also causes an issue.
{ "date": null }

Most helpful comment

You might need to call .nullSafe() before installing it. Can you provide an executable test case so we can match what you're seeing?

All 2 comments

You might need to call .nullSafe() before installing it. Can you provide an executable test case so we can match what you're seeing?

@JakeWharton, thank you for your help, nullSafe() resolved my issue.

Was this page helpful?
0 / 5 - 0 ratings