@@ -49,30 +49,67 @@ public class WebExchangeBindException extends ServerWebInputException implements
49
49
50
50
51
51
public WebExchangeBindException (MethodParameter parameter , BindingResult bindingResult ) {
52
- super ("Validation failure" , parameter , null , null , initMessageDetailArguments ( bindingResult ) );
52
+ super ("Validation failure" , parameter , null , null , null );
53
53
this .bindingResult = bindingResult ;
54
54
getBody ().setDetail ("Invalid request content." );
55
55
}
56
56
57
- private static Object [] initMessageDetailArguments (BindingResult bindingResult ) {
57
+
58
+ /**
59
+ * Return the BindingResult that this BindException wraps.
60
+ * <p>Will typically be a BeanPropertyBindingResult.
61
+ * @see BeanPropertyBindingResult
62
+ */
63
+ public final BindingResult getBindingResult () {
64
+ return this .bindingResult ;
65
+ }
66
+
67
+
68
+ @ Override
69
+ public Object [] getDetailMessageArguments () {
70
+ return new Object [] {
71
+ join (MethodArgumentNotValidException .errorsToStringList (getGlobalErrors ())),
72
+ join (MethodArgumentNotValidException .errorsToStringList (getFieldErrors ()))};
73
+ }
74
+
75
+ @ Override
76
+ public Object [] getDetailMessageArguments (MessageSource source , Locale locale ) {
58
77
return new Object [] {
59
- join (MethodArgumentNotValidException .errorsToStringList (bindingResult .getGlobalErrors ())),
60
- join (MethodArgumentNotValidException .errorsToStringList (bindingResult .getFieldErrors ()))};
78
+ join (MethodArgumentNotValidException .errorsToStringList (getGlobalErrors (), source , locale )),
79
+ join (MethodArgumentNotValidException .errorsToStringList (getFieldErrors (), source , locale ))
80
+ };
61
81
}
62
82
63
83
private static String join (List <String > errors ) {
64
84
return String .join (", and " , errors );
65
85
}
66
86
67
87
/**
68
- * Return the BindingResult that this BindException wraps.
69
- * <p>Will typically be a BeanPropertyBindingResult.
70
- * @see BeanPropertyBindingResult
88
+ * Resolve global and field errors to messages with the given
89
+ * {@link MessageSource} and {@link Locale}.
90
+ * @return a Map with errors as key and resolves messages as value
91
+ * @since 6.0.3
71
92
*/
72
- public final BindingResult getBindingResult () {
73
- return this .bindingResult ;
93
+ public Map <ObjectError , String > resolveErrorMessages (MessageSource messageSource , Locale locale ) {
94
+ Map <ObjectError , String > map = new LinkedHashMap <>();
95
+ addMessages (map , getGlobalErrors (), messageSource , locale );
96
+ addMessages (map , getFieldErrors (), messageSource , locale );
97
+ return map ;
74
98
}
75
99
100
+ private static void addMessages (
101
+ Map <ObjectError , String > map , List <? extends ObjectError > errors ,
102
+ MessageSource messageSource , Locale locale ) {
103
+
104
+ List <String > messages = MethodArgumentNotValidException .errorsToStringList (errors , messageSource , locale );
105
+ for (int i = 0 ; i < errors .size (); i ++) {
106
+ map .put (errors .get (i ), messages .get (i ));
107
+ }
108
+ }
109
+
110
+
111
+ // BindingResult implementation methods
112
+
76
113
@ Override
77
114
public String getObjectName () {
78
115
return this .bindingResult .getObjectName ();
@@ -285,6 +322,7 @@ public String[] getSuppressedFields() {
285
322
return this .bindingResult .getSuppressedFields ();
286
323
}
287
324
325
+
288
326
/**
289
327
* Returns diagnostic information about the errors held in this object.
290
328
*/
@@ -302,38 +340,6 @@ public String getMessage() {
302
340
return sb .toString ();
303
341
}
304
342
305
- @ Override
306
- public Object [] getDetailMessageArguments (MessageSource source , Locale locale ) {
307
- return new Object [] {
308
- join (MethodArgumentNotValidException .errorsToStringList (getGlobalErrors (), source , locale )),
309
- join (MethodArgumentNotValidException .errorsToStringList (getFieldErrors (), source , locale ))
310
- };
311
- }
312
-
313
- /**
314
- * Resolve global and field errors to messages with the given
315
- * {@link MessageSource} and {@link Locale}.
316
- * @return a Map with errors as key and resolves messages as value
317
- * @since 6.0.3
318
- */
319
- public Map <ObjectError , String > resolveErrorMessages (MessageSource messageSource , Locale locale ) {
320
- Map <ObjectError , String > map = new LinkedHashMap <>();
321
- addMessages (map , getGlobalErrors (), messageSource , locale );
322
- addMessages (map , getFieldErrors (), messageSource , locale );
323
- return map ;
324
- }
325
-
326
- private static void addMessages (
327
- Map <ObjectError , String > map , List <? extends ObjectError > errors ,
328
- MessageSource messageSource , Locale locale ) {
329
-
330
- List <String > messages = MethodArgumentNotValidException .errorsToStringList (errors , messageSource , locale );
331
- for (int i = 0 ; i < errors .size (); i ++) {
332
- map .put (errors .get (i ), messages .get (i ));
333
- }
334
- }
335
-
336
-
337
343
@ Override
338
344
public boolean equals (@ Nullable Object other ) {
339
345
return (this == other || this .bindingResult .equals (other ));
0 commit comments