17
17
package org .springframework .validation .method ;
18
18
19
19
import java .lang .reflect .Method ;
20
+ import java .util .Collections ;
20
21
import java .util .List ;
21
22
22
23
import org .springframework .context .MessageSourceResolvable ;
@@ -55,54 +56,75 @@ public interface MethodValidationResult {
55
56
* Whether the result contains any validation errors.
56
57
*/
57
58
default boolean hasErrors () {
58
- return !getAllValidationResults ().isEmpty ();
59
+ return !getParameterValidationResults ().isEmpty ();
59
60
}
60
61
61
62
/**
62
63
* Return a single list with all errors from all validation results.
63
- * @see #getAllValidationResults ()
64
+ * @see #getParameterValidationResults ()
64
65
* @see ParameterValidationResult#getResolvableErrors()
65
66
*/
66
67
default List <? extends MessageSourceResolvable > getAllErrors () {
67
- return getAllValidationResults ().stream ()
68
+ return getParameterValidationResults ().stream ()
68
69
.flatMap (result -> result .getResolvableErrors ().stream ())
69
70
.toList ();
70
71
}
71
72
73
+ /**
74
+ * Return all validation results per method parameter, including both
75
+ * {@link #getValueResults()} and {@link #getBeanResults()}.
76
+ * <p>Use {@link #getCrossParameterValidationResults()} for access to errors
77
+ * from cross-parameter validation.
78
+ * @since 6.2
79
+ * @see #getValueResults()
80
+ * @see #getBeanResults()
81
+ */
82
+ List <ParameterValidationResult > getParameterValidationResults ();
83
+
72
84
/**
73
85
* Return all validation results. This includes both method parameters with
74
86
* errors directly on them, and Object method parameters with nested errors
75
87
* on their fields and properties.
76
88
* @see #getValueResults()
77
89
* @see #getBeanResults()
90
+ * @deprecated deprecated in favor of {@link #getParameterValidationResults()}
78
91
*/
79
- List <ParameterValidationResult > getAllValidationResults ();
92
+ @ Deprecated (since = "6.2" , forRemoval = true )
93
+ default List <ParameterValidationResult > getAllValidationResults () {
94
+ return getParameterValidationResults ();
95
+ }
80
96
81
97
/**
82
- * Return the subset of {@link #getAllValidationResults () allValidationResults}
98
+ * Return the subset of {@link #getParameterValidationResults () allValidationResults}
83
99
* that includes method parameters with validation errors directly on method
84
100
* argument values. This excludes {@link #getBeanResults() beanResults} with
85
101
* nested errors on their fields and properties.
86
102
*/
87
103
default List <ParameterValidationResult > getValueResults () {
88
- return getAllValidationResults ().stream ()
104
+ return getParameterValidationResults ().stream ()
89
105
.filter (result -> !(result instanceof ParameterErrors ))
90
106
.toList ();
91
107
}
92
108
93
109
/**
94
- * Return the subset of {@link #getAllValidationResults () allValidationResults}
110
+ * Return the subset of {@link #getParameterValidationResults () allValidationResults}
95
111
* that includes Object method parameters with nested errors on their fields
96
112
* and properties. This excludes {@link #getValueResults() valueResults} with
97
113
* validation errors directly on method arguments.
98
114
*/
99
115
default List <ParameterErrors > getBeanResults () {
100
- return getAllValidationResults ().stream ()
116
+ return getParameterValidationResults ().stream ()
101
117
.filter (ParameterErrors .class ::isInstance )
102
118
.map (result -> (ParameterErrors ) result )
103
119
.toList ();
104
120
}
105
121
122
+ /**
123
+ * Return errors from cross-parameter validation.
124
+ * @since 6.2
125
+ */
126
+ List <MessageSourceResolvable > getCrossParameterValidationResults ();
127
+
106
128
107
129
/**
108
130
* Factory method to create a {@link MethodValidationResult} instance.
@@ -112,7 +134,23 @@ default List<ParameterErrors> getBeanResults() {
112
134
* @return the created instance
113
135
*/
114
136
static MethodValidationResult create (Object target , Method method , List <ParameterValidationResult > results ) {
115
- return new DefaultMethodValidationResult (target , method , results );
137
+ return create (target , method , results , Collections .emptyList ());
138
+ }
139
+
140
+ /**
141
+ * Factory method to create a {@link MethodValidationResult} instance.
142
+ * @param target the target Object
143
+ * @param method the target method
144
+ * @param results method validation results, expected to be non-empty
145
+ * @param crossParameterErrors cross-parameter validation errors
146
+ * @return the created instance
147
+ * @since 6.2
148
+ */
149
+ static MethodValidationResult create (
150
+ Object target , Method method , List <ParameterValidationResult > results ,
151
+ List <MessageSourceResolvable > crossParameterErrors ) {
152
+
153
+ return new DefaultMethodValidationResult (target , method , results , crossParameterErrors );
116
154
}
117
155
118
156
/**
0 commit comments