BeanValidation 1.1 spec defines API ExecutableValidator.validateParameters
to validate all constraints placed on the parameters of the given method.
However the API require it to pass an object instance on which the method to validate is invoked:
/**
* Validates all constraints placed on the parameters of the given method.
*
* @param <T> the type hosting the method to validate
* @param object the object on which the method to validate is invoked
* @param method the method for which the parameter constraints is validated
* @param parameterValues the values provided by the caller for the given method's
* parameters
* @param groups the group or list of groups targeted for validation (defaults to
* {@link Default})
* @return a set with the constraint violations caused by this validation;
* will be empty if no error occurs, but never {@code null}
* @throws IllegalArgumentException if {@code null} is passed for any of the parameters
* or if parameters don't match with each other
* @throws ValidationException if a non recoverable error happens during the
* validation process
*/
<T> Set<ConstraintViolation<T>> validateParameters(T object,
Method method,
Object[] parameterValues,
Class<?>... groups);
My question is how can I validate a static method invocation? E.g, the invocation of Foo.bar
method defined below:
public class Foo {
public static void bar(@NotNull String str) {...}
}