Passing list of enum values as HTTP query parameters

Csaba Faragó

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!

Jordi Castilla

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Passing list of enum values as HTTP query parameters

分類Dev

passing optional query string parameters to http service call

分類Dev

Http Query Parameters in UTC in AspNet Core

分類Dev

Passing parameters to external query inside stored procedure in BigQuery

分類Dev

Is there a way to limit query results by values in an IN list?

分類Dev

Passing parameters to middleware in Laravel

分類Dev

Passing parameters to a custom URI

分類Dev

Passing parameters to AngularJS $timeout

分類Dev

Passing parameters to a custom URI

分類Dev

Passing LINQ expressions as parameters

分類Dev

Passing parameters to jest function

分類Dev

Passing parameters to a OPENQUERY

分類Dev

passing BlocProvider with class parameters

分類Dev

Passing parameters to a react component

分類Dev

Error with passing parameters

分類Dev

Maple passing parameters by reference

分類Dev

Iframe not passing url parameters

分類Dev

Passing enum type as parameter in typescript

分類Dev

How to create FUNC Action List with Parameters and Return Values

分類Dev

Template specialization for enum values

分類Dev

Typescript enum values as array

分類Dev

Check enum for multiple values

分類Dev

Golang: Passing structs as parameters of a function

分類Dev

Passing additional parameters to MapStruct mapper

分類Dev

Passing parameters in rmarkdown to the text or headings

分類Dev

Passing parameters to scalameta paradise macro

分類Dev

Angular 6 passing in parameters into URL

分類Dev

Passing parameters in java script function ?

分類Dev

Passing values to a variable