Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class User {
- @NotEmpty
- private String email;
- @JsonProperty(access = Access.WRITE_ONLY)
- @NotEmpty
- private String password;
- // Getters and setters
- ...
- }
- @Path("/register")
- @POST
- public Response register(@Valid User user) {
- ...
- }
- "{"errors":["password may not be empty"]}"
- public class GroupValidationTest {
- public static void main(String[] args) {
- Validator v = Validators.newValidator();
- Model m = new Model();
- m.user = "Harry";
- m.password = "Potter";
- Set<ConstraintViolation<Model>> validate = v.validate(m, INPUT.class);
- System.out.println(validate.size());
- validate = v.validate(m, INPUT.class, OUTPUT.class);
- System.out.println(validate.size());
- validate = v.validate(m, OUTPUT.class);
- System.out.println(validate.size());
- m.password = null;
- validate = v.validate(m, INPUT.class, OUTPUT.class);
- System.out.println(validate.size());
- validate = v.validate(m, OUTPUT.class);
- System.out.println(validate.size());
- }
- public static class Model {
- @NotEmpty(groups={INPUT.class, OUTPUT.class})
- public String user;
- @NotEmpty(groups={INPUT.class})
- public String password;
- }
- public interface INPUT {}
- public interface OUTPUT {}
- }
- 0 -> Full object, validate INPUT
- 0 -> Full object, validate INPUT + OUTPUT
- 0 -> Full object, validate OUTPUT
- 1 -> null password, validate INPUT + OUTPUT
- 0 -> null password, validate OUTPUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement