We are using Spring MVC in our Scala application and I would like to figure out how to unwrap Scala Option
's so they can be properly converted using @RequestParam
. I think the solution may have something to do with the Formatter SPI, but I am unsure how to get this to work nicely given that Option
's can contain any number of values (which I'd want Spring to handle normally, as if the converted value were not an Option
at all). In essence, I'd almost want to apply an additional conversion of a value to be Option
wrapped after normal conversion takes place.
For example, given the following code:
@RequestMapping(method = Array(GET), value = Array("/test"))
def test(@RequestParam("foo") foo: Option[String]): String
The url /test
should result in the foo
parameter getting a value of None
, while the url /test?foo=bar
should result in the foo
parameter getting a value of Some("bar")
(/test?foo
could result in either an empty String, or None
).