Description
DefaultErrorAttributes
recognizes BindingResult
exceptions such as MethodArgumentNotValidException
, and adds an "errors" field to the response. This is further controlled with the property server.error.include-binding-errors
.
As of Spring Framework 6.1, built-in method validation can raise HandlerMethodValidationException
instead when there are method parameter constraints. Beyond web endpoints, any Spring component with a validation proxy can raise MethodValidationException
. Both implement MethodValidationResult
.
BindingResult
includes errors for a single method parameter (command object), while MethodValidationResult
includes errors for all validated method parameters, either ParameterValidationResult
(for constraints directly on method parameter) or ParameterErrors
(constraints on properties of command object). The latter is the equivalent of a BindingResult
for the method parameter when method validation is used.
DefaultErrorAttributes
should support exceptions of type MethodValidationResult
in addition to BindingResult
. I think server.error.include-binding-errors
could be extended to cover errors for all parameters, but it should at least properly handle and include any ParameterErrors
, or otherwise there is no "errors" field at all as reported in spring-projects/spring-framework#32396.