public static <T> Collection<String> format(Set<ConstraintViolation<T>> violations) { final SortedSet<String> errors = new TreeSet<>(); for (ConstraintViolation<?> v : violations) { errors.add(format(v)); } return errors; }
public static Collection<String> formatUntyped(Set<ConstraintViolation<?>> violations) { final SortedSet<String> errors = new TreeSet<>(); for (ConstraintViolation<?> v : violations) { errors.add(format(v)); } return errors; }
/** * Creates a new ConfigurationException for the given path with the given errors. * * @param path the bad configuration path * @param errors the errors in the path */ public <T> ConfigurationValidationException(String path, Set<ConstraintViolation<T>> errors) { super(path, ConstraintViolations.format(errors)); this.constraintViolations = ConstraintViolations.copyOf(errors); }
public static ImmutableList<String> formatUntyped(Set<ConstraintViolation<?>> violations) { final Set<String> errors = new HashSet<>(); for (ConstraintViolation<?> v : violations) { errors.add(format(v)); } return ImmutableList.copyOf(Ordering.natural().sortedCopy(errors)); }
public static <T> ImmutableList<String> format(Set<ConstraintViolation<T>> violations) { final Set<String> errors = new HashSet<>(); for (ConstraintViolation<?> v : violations) { errors.add(format(v)); } return ImmutableList.copyOf(Ordering.natural().sortedCopy(errors)); }
/** * Creates a new ConfigurationException for the given path with the given errors. * * @param path the bad configuration path * @param errors the errors in the path */ public <T> ConfigurationValidationException(String path, Set<ConstraintViolation<T>> errors) { super(path, ConstraintViolations.format(errors)); this.constraintViolations = ConstraintViolations.copyOf(errors); }
/** * Copied and modified from com.yammer.dropwizard.jersey.jackson#JacksonMessageBodyProvider.validate() * Notes on Hibernate Validator: * - when validating object graphs, null references are ignored. * - from version 5 on, Hibernate Validator throws IllegalArgumentException instead of ValidationException * for null parameter values: * java.lang.IllegalArgumentException: HV000116: The object to be validated must not be null. */ private Object validate(Annotation[] annotations, Object value) { final Class<?>[] classes = findValidationGroups(annotations); if (classes != null) { final ImmutableList<String> errors = ConstraintViolations.format( validator.validate(value, classes)); if (!errors.isEmpty()) { String message = "\n"; for (String error : errors) { message += " " + error + "\n"; } throw new ValidationException(message); } } return value; }