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 Option
s well, and I want it to pass Seq
to my custom QueryStringBindable
, how to achieve this?
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
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.
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 ...
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With