I need to send an array of type User[]
in the body of a GET request using retrofit2. This is what the final payload must look like:
body: {
"data_id": 1,
"data_provider": "string_value",
"users": [
{
user_id: 1,
name: 'name'
},
{
user_id: 1,
name: 'name'
},
...
]
}
Current API implementation looks like this:
@GET("api/users/submit.json")
Call<UserData> submitData(@Query("data_id") int data_id, @Query("data_provider") String data_provider, @Query("users[]") User[] users);
Arraylist code:
//Converting the ArrayList<User> usersList to an array
User[] userArray = usersList.toArray(new User[0]);
//The userArray is passed to the retrofit API along with the other request values (data_id, data_provider)
Upon logging the retrofit request, data_id
and data_provider
are correctly sent except for the User array. The user array looks like this:
api/users/submit.json?data_id=1&data_provider=test&users[]=com.testapp.models.User@7d57487
How can I send an array of type User
in the GET request body?