Search code examples
androidretrofitretrofit2

Add an array as request parameter with Retrofit 2


I'm looking for way to add an int array (e.g [0,1,3,5]) as parameter in a GET request with retrofit 2. Then, the generated url should be like this : http://server/service?array=[0,1,3,5]

How to do this ?


Solution

  • I have finally founded a solution by using Arrays.toString(int []) method and by removing spaces in this result because Arrays.toString return "[0, 1, 3, 5]". And my request method looks like this

    @GET("http://server/service")
    Observable<Void> getSomething(@Query("array") String array);