Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling
Created January 4, 2019 10:35
Show Gist options
  • Save gunnarmorling/c7b7f5e72999bad4e1d24ee110917664 to your computer and use it in GitHub Desktop.
Save gunnarmorling/c7b7f5e72999bad4e1d24ee110917664 to your computer and use it in GitHub Desktop.
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
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