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
}
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.
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?