com.alogient.cameleon.sdk.content.validator.ConstraintViolationUtil Maven / Gradle / Ivy
The newest version!
package com.alogient.cameleon.sdk.content.validator;
import com.google.common.collect.Iterators;
import javax.validation.ConstraintViolation;
import java.lang.reflect.Field;
public class ConstraintViolationUtil {
public static String getViolationMessage(final ConstraintViolation> violation) {
return violation.getMessage();
}
public static boolean isRootAndLeafBeanTheSame(final ConstraintViolation> violation) {
return violation.getLeafBean() == violation.getRootBean();
}
public static Field getLeafProperty(final ConstraintViolation> violation) throws NoSuchFieldException {
return violation.getLeafBean().getClass().getDeclaredField(getLeafPropertyName(violation));
}
public static String getLeafPropertyName(final ConstraintViolation> violation) {
return Iterators.getLast(violation.getPropertyPath().iterator()).getName();
}
public static String getConstraintAnnotationName(final ConstraintViolation> violation) {
return violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName();
}
public static String getPropertyPath(final ConstraintViolation> violation) {
return violation.getPropertyPath().toString();
}
public static String getRootBeanName(final ConstraintViolation> violation) {
return violation.getRootBeanClass().getSimpleName();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy