32
32
public interface MethodValidator {
33
33
34
34
/**
35
- * Use this method to determine the validation groups.
35
+ * Determine the applicable validation groups. By default, obtained from an
36
+ * {@link org.springframework.validation.annotation.Validated @Validated}
37
+ * annotation on the method, or on the class level.
36
38
* @param target the target Object
37
39
* @param method the target method
38
40
* @return the applicable validation groups as a {@code Class} array
39
41
*/
40
42
Class <?>[] determineValidationGroups (Object target , Method method );
41
43
42
44
/**
43
- * Validate the given method arguments and handle the result .
45
+ * Validate the given method arguments and return validation results .
44
46
* @param target the target Object
45
47
* @param method the target method
46
48
* @param parameters the parameters, if already created and available
47
49
* @param arguments the candidate argument values to validate
48
- * @param groups validation groups via {@link #determineValidationGroups}
49
- * @throws MethodValidationException raised by default in case of validation errors.
50
- * Implementations may provide alternative handling, possibly not raise an exception
51
- * but for example inject errors into the method, or raise a different exception,
52
- * one that also implements {@link MethodValidationResult}.
50
+ * @param groups validation groups from {@link #determineValidationGroups}
51
+ * @return the result of validation
52
+ */
53
+ MethodValidationResult validateArguments (
54
+ Object target , Method method , @ Nullable MethodParameter [] parameters ,
55
+ Object [] arguments , Class <?>[] groups );
56
+
57
+ /**
58
+ * Delegate to {@link #validateArguments} and handle the validation result,
59
+ * by default raising {@link MethodValidationException} in case of errors.
60
+ * Implementations may provide alternative handling, e.g. injecting
61
+ * {@link org.springframework.validation.Errors} into the method.
62
+ * @throws MethodValidationException in case of unhandled errors.
53
63
*/
54
64
default void applyArgumentValidation (
55
65
Object target , Method method , @ Nullable MethodParameter [] parameters ,
@@ -62,28 +72,23 @@ default void applyArgumentValidation(
62
72
}
63
73
64
74
/**
65
- * Validate the given method arguments and return validation results.
75
+ * Validate the given return value and return validation results.
66
76
* @param target the target Object
67
77
* @param method the target method
68
- * @param parameters the parameters , if already created and available
69
- * @param arguments the candidate argument values to validate
78
+ * @param returnType the return parameter , if already created and available
79
+ * @param returnValue the return value to validate
70
80
* @param groups validation groups from {@link #determineValidationGroups}
71
81
* @return the result of validation
72
82
*/
73
- MethodValidationResult validateArguments (
74
- Object target , Method method , @ Nullable MethodParameter [] parameters ,
75
- Object [] arguments , Class <?>[] groups );
83
+ MethodValidationResult validateReturnValue (
84
+ Object target , Method method , @ Nullable MethodParameter returnType ,
85
+ @ Nullable Object returnValue , Class <?>[] groups );
76
86
77
87
/**
78
- * Validate the given return value and handle the results.
79
- * @param target the target Object
80
- * @param method the target method
81
- * @param returnType the return parameter, if already created and available
82
- * @param returnValue the return value to validate
83
- * @param groups validation groups from {@link #determineValidationGroups}
84
- * @throws MethodValidationException raised by default in case of validation errors.
85
- * Implementations may provide alternative handling, or raise a different exception,
86
- * one that also implements {@link MethodValidationResult}.
88
+ * Delegate to {@link #validateReturnValue} and handle the validation result,
89
+ * by default raising {@link MethodValidationException} in case of errors.
90
+ * Implementations may provide alternative handling.
91
+ * @throws MethodValidationException in case of unhandled errors.
87
92
*/
88
93
default void applyReturnValueValidation (
89
94
Object target , Method method , @ Nullable MethodParameter returnType ,
@@ -95,17 +100,4 @@ default void applyReturnValueValidation(
95
100
}
96
101
}
97
102
98
- /**
99
- * Validate the given return value and return the result of validation.
100
- * @param target the target Object
101
- * @param method the target method
102
- * @param returnType the return parameter, if already created and available
103
- * @param returnValue the return value to validate
104
- * @param groups validation groups from {@link #determineValidationGroups}
105
- * @return the result of validation
106
- */
107
- MethodValidationResult validateReturnValue (
108
- Object target , Method method , @ Nullable MethodParameter returnType ,
109
- @ Nullable Object returnValue , Class <?>[] groups );
110
-
111
103
}
0 commit comments