Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple of the same/array parameter using Retrofit?

I have an instance where I need to pass multiple of the same named parameters to a server (array of data).

Changing it is not a possibility.

http://test.com?test[]=1&test[]=2&test[]=3

How do I accomplish this with RetroFit? I see that you can pass a map of values, but that doesn't help as the keys are all identical.

Any help would be great... really hoping there's a clean way/workaround or else I'm going to need to use another api lib and do a project refactor.

like image 422
loeschg Avatar asked Feb 19 '14 20:02

loeschg


2 Answers

Retrofit as of 1.4.0 added the ability to send an array or List as a @Field or @Query parameter.

New: @Query and @EncodedQuery now accept List or arrays for multiple values.
New: @Field now accepts List or arrays for multiple values.
like image 112
daentech Avatar answered Oct 16 '22 22:10

daentech


I am using retrofit:1.9.0, one way of doing http://test.com?test[]=1&test[]=2&test[]=3 is like this

void test(@Query("test[]") ArrayList<String> values);
like image 28
Mostafa Abdellateef Avatar answered Oct 16 '22 23:10

Mostafa Abdellateef