Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.0: Optional list in query

I'm trying to define a route with an optional list as query parameter

GET /places controllers.Application.query(filter: Option[Seq[Int]])

but getting this error

conf/routes - PlayException: Compilation error [`)' expected but `]' found]

I know Play 2 handles Options well, and I want it to pass Seq to my custom QueryStringBindable, how to achieve this?

like image 696
lambdas Avatar asked Jul 06 '12 08:07

lambdas


People also ask

How to add optional query parameters to an API query?

5 For optional Query parameters, you can do it this way In routes file, declare API GET /birthdays controllers.Application.method(from: Long, to: Long) You can also give some default value, in case API doesn't contain these query params it will automatically assign the default values to these params

What is the optional parameter for sort query?

Optional Query Parameters Depending on the API design, the sort parameter might be optional. In case you don’t want to pass it with the request, just pass null as the value for order during method call.

What is the use of optional in Java?

As of JDK 7, Java includes the Optional class, which allows developers to return values that may or may not be present and allows clients to handle these cases according to the context in which ...

What are “and” Queries?

These are those queries where you are pulling for, let’s say, a first name, a last name, a state, and/or a city. Simple enough, until you notice that or. We might only get a first name, or a state and the query still needs to work. These queries are commonly called And a bunch of things that aren’t really printable here.


1 Answers

It seems like Play 2.0.2 routing parser doesn't support nesting type parameters. I've found workaround, I've defined alias for Seq[Int]:

type IntSeq = Seq[Int]

and used it instead of original type:

GET /places controllers.Application.query(filter: Option[IntSeq])

Now it works as expected.

like image 131
lambdas Avatar answered Oct 18 '22 14:10

lambdas