Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

android - How to send PATCH request and change field to NULL?

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?

question from:https://stackoverflow.com/questions/65829444/how-to-send-patch-request-and-change-field-to-null

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...