I've got a Play! 2 routes file and controller that looks something like this:
GET /books BooksController.getBooks(author: play.libs.F.Option[String])
public class BooksController extends Controller {
public static Result getBooks(play.libs.F.Option<String> author) {
...
}
}
I would like to refactor it to use Java 8's Optional, but this causes a compilation error:
GET /books BooksController.getBooks(author: java.util.Optional[String])
public class BooksController extends Controller {
public static Result getBooks(java.util.Optional<String> author) {
...
}
}
I've tried creating a custom QueryStringBindable, but that forces me to type the controller's parameters as the bindable's type, not Optional. Any other ways of doing this? Thanks.
It is not possible right now. There is an github issue to replace F.Option with java.util.Optional. It will be delivered in Playframework 2.5.0.
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