3

I am using Retrofit 2.9.0 to send network requests:

val retrofit = Retrofit.Builder()
  .baseUrl(BuildConfig.API_URL)
  .addConverterFactory(MoshiConverterFactory.create(moshi))
  .build()
return retrofit.create(ApiService::class.java)

and Moshi 2.4.0 for JSON serialization:

Moshi.Builder().build()

I have some model with a next field which can be null:

data class ChangeDutyEvent(
  @field:Json(name = "signature_date") var signatureDate: String? = null,
  ...
)

When I send PATCH request with some not null value of this field, it is working normaly - value updates on server. But when I send the same request with null value, its value on server is still not null. So, I think Retrofit or Moshi ignore null, how I can fix it?

MaxAstin
  • 463
  • 5
  • 14

1 Answers1

0

In my case, it works like that.

 val retrofit = Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create(moshi).withNullSerialization())
                        .baseUrl(BuildConfig.API_URL)
                        .build()