Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing list of enum values as HTTP query parameters

I want to pass list of enum values as HTTP query parameter. The entry point of the server side looks like this:

@GET
@Path("/getMyResult")
public MyResultType getMyResult(@QueryParam("me") final List<MyEnum> myEnums) 

This cannot be modified. Consider MyEnum contains values MyValue1, MyValue2, MyValue3 and MyValue4. (MyResultType is not relevant for this question.) Passing only one value, as follows, works fine (which is a bit strange for me):

http://localhost/getMyResult?me=MyValue1

However, passing list of elements this way:

http://localhost/getMyResult?me=[MyValue1,MyValue3,MyValue4]

or this way:

http://localhost/getMyResult?me=MyValue1,MyValue3,MyValue4

or this way:

http://localhost/getMyResult?me=["MyValue1","MyValue3","MyValue4"]

does not work, it throws exception something like this (error message to the first option):

RESTEASY001720: Unable to extract parameter from http request: javax.ws.rs.QueryParam(\"me\") [...]
No enum constant com.mycompany.myapp.MyEnum.[MyValue1,MyValue3,MyValue4]

Can anyone tell me how to pass a list of MyEnum elements as HTTP GET query parameter? Thank you!

like image 485
Csaba Faragó Avatar asked May 04 '16 11:05

Csaba Faragó


1 Answers

For this (and other cases you need to pass a List) you must insert name of the parameter for each element.

In this way:

http://localhost/getMyResult?me=MyValue1&me=MyValue3&me=MyValue4
like image 164
Jordi Castilla Avatar answered Nov 10 '22 06:11

Jordi Castilla