Search code examples
javalistresteasyquery-string

How to support comma separated list queryParam in RestEasy


When using a list as a QueryParam in RestEasy, (@QueryParam List strings), following url works fine - ?strings=123&strings=456 this works and you get list with 2 values.

but when you pass the value as follows - ?strings=123,456 it gives "123,456" as a single value which is not expected behaviour.

How to get strings=123,456 as a List of 123 and 456.

One option is to create Provider class for Set and modify the fromString and toString method, after this strings=123,456 start working and it gives list with two elements and 123 and 456, but strings=123&strings=456 dont work now and it gives list with only one element 123.

Let me know how can i get both the behaviour in RestEasy QueryParam.


Solution

  • I fixed this issue by implementing ContainerRequestFilter and in the filter method updated the actual URL and set it back into requestContext. e.g. original URl - http://localhost:8080/api?tags=123,456

    updated Url - http://localhost:8080/api?tags=123&tags=456