Package org.springframework.web.bind
Class MethodArgumentNotValidException
java.lang.Object
java.lang.Throwable
java.lang.Exception
org.springframework.validation.BindException
org.springframework.web.bind.MethodArgumentNotValidException
- All Implemented Interfaces:
Serializable
,BindingResult
,Errors
,ErrorResponse
Exception to be thrown when validation on an argument annotated with
@Valid
fails.
Extends BindException
as of 5.3.- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse
ErrorResponse.Builder
-
Field Summary
Fields inherited from interface org.springframework.validation.BindingResult
MODEL_KEY_PREFIX
Fields inherited from interface org.springframework.validation.Errors
NESTED_PATH_SEPARATOR
-
Constructor Summary
ConstructorDescriptionMethodArgumentNotValidException
(MethodParameter parameter, BindingResult bindingResult) Constructor forMethodArgumentNotValidException
. -
Method Summary
Modifier and TypeMethodDescriptionerrorsToStringList
(List<? extends ObjectError> errors) Deprecated, for removal: This API element is subject to removal in a future version.errorsToStringList
(List<? extends ObjectError> errors, MessageSource messageSource, Locale locale) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofBindErrorUtils
, to be removed in 6.2getBody()
Return the body for the response, formatted as an RFC 7807ProblemDetail
whosestatus
should match the response status.Object[]
Return arguments to use along with amessage code
to resolve the problem "detail" for this exception through aMessageSource
.Object[]
getDetailMessageArguments
(MessageSource source, Locale locale) Variant ofErrorResponse.getDetailMessageArguments()
that uses the givenMessageSource
for resolving the message argument values.Returns diagnostic information about the errors held in this object.final MethodParameter
Return the method parameter that failed validation.Return the HTTP status code to use for the response.resolveErrorMessages
(MessageSource messageSource, Locale locale) Deprecated, for removal: This API element is subject to removal in a future version.in favor of usingBindErrorUtils
andBindException.getAllErrors()
, to be removed in 6.2Methods inherited from class org.springframework.validation.BindException
addAllErrors, addError, equals, findEditor, getAllErrors, getBindingResult, getErrorCount, getFieldError, getFieldError, getFieldErrorCount, getFieldErrorCount, getFieldErrors, getFieldErrors, getFieldType, getFieldValue, getGlobalError, getGlobalErrorCount, getGlobalErrors, getModel, getNestedPath, getObjectName, getPropertyEditorRegistry, getRawFieldValue, getSuppressedFields, getTarget, hasErrors, hasFieldErrors, hasFieldErrors, hasGlobalErrors, hashCode, popNestedPath, pushNestedPath, recordFieldValue, recordSuppressedField, reject, reject, reject, rejectValue, rejectValue, rejectValue, resolveMessageCodes, resolveMessageCodes, setNestedPath
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.web.ErrorResponse
getDetailMessageCode, getHeaders, getTitleMessageCode, getTypeMessageCode, updateAndGetBody
-
Constructor Details
-
MethodArgumentNotValidException
Constructor forMethodArgumentNotValidException
.- Parameters:
parameter
- the parameter that failed validationbindingResult
- the results of the validation
-
-
Method Details
-
getParameter
Return the method parameter that failed validation. -
getStatusCode
Description copied from interface:ErrorResponse
Return the HTTP status code to use for the response.- Specified by:
getStatusCode
in interfaceErrorResponse
-
getBody
Description copied from interface:ErrorResponse
Return the body for the response, formatted as an RFC 7807ProblemDetail
whosestatus
should match the response status.- Specified by:
getBody
in interfaceErrorResponse
-
getDetailMessageArguments
Description copied from interface:ErrorResponse
Variant ofErrorResponse.getDetailMessageArguments()
that uses the givenMessageSource
for resolving the message argument values.This is useful for example to expand message codes from validation errors.
The default implementation delegates to
ErrorResponse.getDetailMessageArguments()
, ignoring the suppliedMessageSource
andLocale
.- Specified by:
getDetailMessageArguments
in interfaceErrorResponse
- Parameters:
source
- theMessageSource
to use for the lookuplocale
- theLocale
to use for the lookup
-
getDetailMessageArguments
Description copied from interface:ErrorResponse
Return arguments to use along with amessage code
to resolve the problem "detail" for this exception through aMessageSource
. The arguments are expanded into placeholders of the message value, e.g. "Invalid content type {0}".- Specified by:
getDetailMessageArguments
in interfaceErrorResponse
-
errorsToStringList
@Deprecated(since="6.1", forRemoval=true) public static List<String> errorsToStringList(List<? extends ObjectError> errors) Deprecated, for removal: This API element is subject to removal in a future version.in favor of usingBindErrorUtils
andBindException.getAllErrors()
, to be removed in 6.2Convert each givenObjectError
to a String.- Since:
- 6.0
-
errorsToStringList
@Deprecated(since="6.1", forRemoval=true) public static List<String> errorsToStringList(List<? extends ObjectError> errors, @Nullable MessageSource messageSource, Locale locale) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofBindErrorUtils
, to be removed in 6.2Convert each givenObjectError
to a String, and use aMessageSource
to resolve each error.- Since:
- 6.0
-
resolveErrorMessages
@Deprecated(since="6.1", forRemoval=true) public Map<ObjectError,String> resolveErrorMessages(MessageSource messageSource, Locale locale) Deprecated, for removal: This API element is subject to removal in a future version.in favor of usingBindErrorUtils
andBindException.getAllErrors()
, to be removed in 6.2Resolve global and field errors to messages with the givenMessageSource
andLocale
.- Returns:
- a Map with errors as keys and resolved messages as values
- Since:
- 6.0.3
-
getMessage
Description copied from class:BindException
Returns diagnostic information about the errors held in this object.- Overrides:
getMessage
in classBindException
-
BindErrorUtils
andBindException.getAllErrors()
, to be removed in 6.2