I am trying to write a GET method and send array of int's as QueryParam to it. This is how I am trying to do:
@GET
@Path("/test")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response test(@Context HttpServletRequest request,
@QueryParam("list") final int list[])
{
System.out.println(list.length);
return Response.ok().build();
}
This results in 500 Internal Server error.When I tried using List of Integer, it worked perfectly. Doesn't Jersey support array as parameter or am I doing something wrong?
The implementation of this in jersey which is not supporting array as a parameter. As you need to pass it as an array just pass it by converting the list to array by using Arrays.asList(arr)
The java doc say that the type of method parameter should be :
1) Be a primitive type;
2) Have a constructor that accepts a single String argument;
3) Have a static method named valueOf or fromString that accepts a single String argument (see, for example, Integer.valueOf(String))
4) Be List, Set or SortedSet, where T satisfies 2 or 3 above. The resulting collection is read-only.
Sometimes parameters may contain more than one value for the same name. If this is the case then types in 4) may be used to obtain all values.
So using an array would not be possible in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With