On Dec 29, 2010, at 6:39 PM, mauricio munoz wrote:
> Hello all,
>
> I want to know how do I pass a parameter as a list to a resource
> method. I know that I can have a list as a PathParam, but I don't
> know how should I pass the list on the url.
>
> I want to be able to call a service like this:
>
> @GET
> @Path("/somepath/{ids}")
> public List<Long> showList(@PathParam("ids") List<Long> ids) {
> return ids;
> }
>
> It seems like my method is ok. I was trying with something like /
> myresource/somepath/1,2,3,4 expecting to get the {1,2,3,4} list but
> it didn't work.
>
The support for collection types is for when multiple parameter names
are present and is not for parsing the value of a parameter, since the
format of the parameter value is unknown, you choose "," someone else
wants " ", and another "-" as the separator.
As Naresh indicates you can write your own class:
public class CommaSeparatedList extends ArrayList<String> {
public CommaSeparatedList(String v) {
super(Arrays.toList(v.split(","));
}
}
Paul.