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);
私の質問は、私は、静的メソッドの呼び出しを検証することができる方法ですか?例えば、以下に定義Foo.bar
メソッドの呼び出し:
public class Foo {
public static void bar(@NotNull String str) {...}
}
はじめに静的メソッドを検証する理由を教えてください。 staticの定義により、Beanの検証はもう行われません。 – Tunaki
私はBean 'Foo'を検証していません。しかし、私は上記のサンプルコードでパラメータ 'str'を検証する必要があります –