Last active
October 26, 2020 03:04
-
-
Save operando/9e7ebeece0e3c8a637580ee100d77834 to your computer and use it in GitHub Desktop.
How to send empty array param with Retrofit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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