Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Play! framework form validations
package controllers;
// Java
import java.util.*;
// Play
import play.*;
import play.mvc.*;
import play.libs.Json;
import models.*;
import com.fasterxml.jackson.databind.JsonNode;
public class Users extends Controller {
public static Result newUser() {
Form<UserCreate> userCreateForm = Form.form(UserCreate.class);
userCreateForm = userCreateForm.bind(request().body().asJson());
if (userCreateForm.hasErrors()) {
return badRequest(userCreateForm.errorsAsJson());
} else {
UserCreate userCreate = userCreateForm.bindFromRequest().get();
User user = User.create(;
return created(Json.toJson(user));
public static class UserCreate {
public String email;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment