Question

I want to use a web service that accepts a String[] array in the body of the web request.

public void fooWebService(@RequestBody String[] ids)

What would be the best way to send the String[] array from my Android client using Retrofit? I am assuming I would need to use the @Body annotation.

The content-type is application/json.

Was it helpful?

Solution

Retrofit's default serialization is JSON so this will basically work out-of-the-box. You can use either a String[] or List<String> on the client (I prefer the latter).

@POST("/endpoint")
void sendIds(@Body List<String> ids);

After creating an instance of the service using your RestAdapter you can pass an existing list of IDs or create one.

service.sendIds(ids);
// .. or ..
service.sendIds(Arrays.asList("foo", "bar"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top