Can I use varargs in a retrofit method declaration?
java, retrofit
Solution
Retrofit can't know how you want to join the strings in the path. While commas seem obvious, there's no reason why someone might want pipes (`|`) or colons (`:`) or whatever.
Because of this fact, we don't do anything and rely on you to choose.
There's two solutions to this:
Use `String` as the argument type and join at the call site. For example:
foo.getObject(Joiner.on(',').join(things));
Use a custom object whose `toString()` method deals with returning the correct format for one or many objects.
Problem
I've got an API endpoint that is defined as: `GET https://api-server.com/something/{id_or_ids}` where `ids` can be a single object id or a comma separated list of ids. e.g. `https://api-server.com/something/abcd1234` `https://api-server.com/something/abcd1234,abcd4567,gdht64332` if a single id is given (and a matching object is found) I get back a json object: `{ "blah" : "blah" }` If multiple ids are given, I get the response in a json array: `[{"blah1":"bleh"}, {"blah2":"meh"}, {"blah3":"blah"}]` I'm currently thinking that I should implement this as two methods (can it be done in one?): one that takes a single id and returns a single object: ``` @GET("/something/{id}") void getObject (@Path("id") String objectId, Callback<MyObject> callback) ``` and one that takes multiple ids and returns an array of objects. ``` @GET("/something/{ids}") void getObject (Callback<MyObject[]> callback,@Path("ids") String ... objectIds) ``` Is there a way to feed the 2nd method varargs and concatenate them in the id field? Thanks