Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Hibernate Validator, declare and validate application constraints
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <>.
package org.hibernate.validator.test.internal.engine.valueextraction;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.constraints.Size;
* @author Gunnar Morling
public class Main {
public static class Foo {
public Map<String, @Size(max=5) String> values = new HashMap<>();
public static void main(String[] args) {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Foo foo1 = new Foo();
foo1.values.put("Test", "Too Long");
Set<ConstraintViolation<Foo>> violations = validator.validate(foo1);
System.out.println( violations );
Foo foo2 = new Foo();
foo2.values.put("Test", "Too Long");
violations = validator.validate(foo2);
System.out.println( violations );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment