use of com.flytecnologia.core.exception.InvalidDataException in project flytecnologia-api by jullierme.
the class FlyValidatorUtil method validate.
public static void validate(Object entry, Class<?> targetClass, String methodName) throws MethodArgumentNotValidException {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(entry, entry.getClass().getName());
validator.validate(entry, errors);
if (errors.hasErrors()) {
Method method = null;
for (Method methodAux : targetClass.getMethods()) {
if (methodAux.getName().equals(methodName)) {
method = methodAux;
break;
}
}
if (method != null) {
MethodParameter methodParameter = new MethodParameter(method, 0);
throw new MethodArgumentNotValidException(methodParameter, errors);
} else {
throw new InvalidDataException(errors.getAllErrors().toString(), errors);
}
}
}
Aggregations