Play! Java 8 Platform Support Optional

I have a Game! 2 routes a file and a 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 Optional

, but this throws 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 tried to create a custom QueryStringBindable , but that forces me to enter the controller parameters as the bindable type instead Optional

. Any other ways to do this? Thank.

+3


source to share


1 answer


It's impossible now. There is a github issue to replace F.Option

with java.util.Optional

. It will be delivered to Playframework 2.5.0

.



+3


source







All Articles