Reputation: 884
I have implemented a rest Query as shown below:
@Path("list")
@GET
public List<Todo> getTodos(@Context UriInfo uriInfo){
MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
List<String> parameterList = queryParameters.get(assignee.name); //Output -> name1,name2 parameterList -- size -1
String parameter = queryParameters.getFirst(assignee.name); //Output -> name1,name2
.
.
.
}
How do I handle when multiple parameters
http://localhost:9090/hello-todo/api/v1/todo/list?assignee.name={name1,name2}
Here instead of two strings, I am getting it as one single string. How should I handle it, should I split the parameter String by comma (,).?
When
Currently it is able to handle these endpoints. The Rest URL's are
http://localhost:9090/hello-todo/api/v1/todo/list
http://localhost:9090/hello-todo/api/v1/todo/list?status=CRITICAL
http://localhost:9090/hello-todo/api/v1/todo/list?status=MAJOR
http://localhost:9090/hello-todo/api/v1/todo/list?status={criticality}&todo.completion.status=completed
http://localhost:9090/hello-todo/api/v1/todo/list?status={criticality}&todo.completion.status=completed&todo.title={title}
http://localhost:9090/hello-todo/api/v1/todo/list?status={criticality}&todo.completion.status=completed&todo.title={title}&todo.startDate={startDate}
Upvotes: 1
Views: 119
Reputation: 32407
If you want queryParameters.get(assignee.name);
to return a list, you can include the parameter more than once in the URL
http://localhost:9090/hello-todo/api/v1/todo/list?assignee.name=name1&assignee.name=name2
Or you can continue to have a single parameter (list?assignee.name=name1,name2
) and split on ,
, but you have to write the code to do that, and consider what to do when one of your names has a ,
character in it.
Upvotes: 1