-
-
Notifications
You must be signed in to change notification settings - Fork 202
Description
Nullability across the framework is expressed using the java.util.Optional class. This is/was a right choice and let users to quickly identify where an optional value might occurs.
Suppose you have a form that will post a Book object with a title an optional releaseDate, you can express this like:
public class Book {
public String title;
public Optional<Date> releaseDate;
}
{
post("/book", req -> {
Book book = req.params(Book.class);
});
}This is nice, clean and add semantic to your business. Book is telling you that releaseDate might not be present.. which is very nice!
...Still, due that Optional was a recent addition to java... isn't widely used it by Java developers... So that is why we are going to support null values when user explicitly ask for it:
{
// true means allowNulls
parser(Parser.bean(true));
post("/book", req -> {
Book book = req.params(Book.class);
});
}So, now you can use `Date releaseDateinstead ofOptional releaseDate``
Source: https://groups.google.com/forum/#!topic/jooby-project/fyjwuXUxjfY
/cc @kshep92