Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! Framework support for Java 8 Optional

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.

like image 609
Jacob Wallace Avatar asked Sep 25 '26 19:09

Jacob Wallace


1 Answers

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.

like image 198
Mon Calamari Avatar answered Sep 28 '26 22:09

Mon Calamari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!