org.s1.web.formats.BeanValidationException Maven / Gradle / Ivy
package org.s1.web.formats;
import javax.validation.ConstraintViolation;
import java.util.Set;
/**
* @author Grigory Pykhov
*/
public class BeanValidationException extends Exception {
private Set> violations;
/**
*
* @param violations ConstraintViolations
*/
public BeanValidationException(Set> violations) {
super(getMessage(violations));
this.violations = violations;
}
/**
*
* @return ConstraintViolations
*/
public Set> getViolations() {
return violations;
}
private static String getMessage(Set> violations){
String message = "";
message+="Got "+violations.size()+" violations:\n";
int i=1;
for(ConstraintViolation violation:violations){
message+=(i++)+") "+violation.getPropertyPath()+" ["+violation.getInvalidValue()+"]: "+violation.getMessage()+"\n";
}
return message;
}
}