1
BeanValidation 1.1规范定义API ExecutableValidator.validateParameters
以验证放置在给定方法参数上的所有约束。JSR 349验证:静态方法上的ExecutableValidator.validateParameters
然而,API要求它传递被调用,以验证方法的对象实例:
/**
* 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);
我的问题是我怎么能验证一个静态方法调用? E.g,下面定义Foo.bar
方法的调用:
public class Foo {
public static void bar(@NotNull String str) {...}
}
为什么你想验证一个静态方法开始?按照静态的定义,你不再验证bean。 – Tunaki
我没有验证bean'Foo'。不过,我需要在提到的示例代码中验证参数'str' –