Skip to content

Instantly share code, notes, and snippets.

@operando
Last active October 26, 2020 03:04
Show Gist options
  • Save operando/9e7ebeece0e3c8a637580ee100d77834 to your computer and use it in GitHub Desktop.
Save operando/9e7ebeece0e3c8a637580ee100d77834 to your computer and use it in GitHub Desktop.
How to send empty array param with Retrofit
// Create RequestBody
FormBody.Builder builder = new FormBody.Builder();
List<String> additionalFields = ...;
if (additionalFields.isEmpty()) {
builder.add("additional_fields[]", "");
} else {
for (String additionalField : additionalFields) {
builder.add("additional_fields[]", additionalField);
}
}
// Send
Api.editApi(builder.build()).enqueue(callback);
// API
interface Api {
@PUT("put_api")
Call<Void> editApi(@Body RequestBody body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment