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 SummaryNested classes/interfaces inherited from interface org.springframework.web.ErrorResponseErrorResponse.Builder
- 
Field SummaryFields inherited from interface org.springframework.validation.BindingResultMODEL_KEY_PREFIXFields inherited from interface org.springframework.validation.ErrorsNESTED_PATH_SEPARATOR
- 
Constructor SummaryConstructorsConstructorDescriptionMethodArgumentNotValidException(Executable executable, BindingResult bindingResult) Constructor forMethodArgumentNotValidException.MethodArgumentNotValidException(MethodParameter parameter, BindingResult bindingResult) Constructor forMethodArgumentNotValidException.
- 
Method SummaryModifier and TypeMethodDescriptionerrorsToStringList(List<? extends ObjectError> errors) Convert each givenObjectErrorto a String in single quotes, taking either the error's default message, or its error code.errorsToStringList(List<? extends ObjectError> errors, MessageSource source, Locale locale) Variant oferrorsToStringList(List)that uses aMessageSourceto resolve the message code of the error, or fall back on the error's default message.getBody()Return the body for the response, formatted as an RFC 7807ProblemDetailwhosestatusshould match the response status.Object[]Return arguments to use along with amessage codeto resolve the problem "detail" for this exception through aMessageSource.Object[]getDetailMessageArguments(MessageSource messageSource, Locale locale) Variant ofErrorResponse.getDetailMessageArguments()that uses the givenMessageSourcefor resolving the message argument values.Returns diagnostic information about the errors held in this object.final MethodParameterReturn the method parameter that failed validation.Return the HTTP status code to use for the response.resolveErrorMessages(MessageSource messageSource, Locale locale) Resolve global and field errors to messages with the givenMessageSourceandLocale.Methods inherited from class org.springframework.validation.BindExceptionaddAllErrors, 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, setNestedPathMethods inherited from class java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.web.ErrorResponsegetDetailMessageCode, getHeaders, getTitleMessageCode, updateAndGetBody
- 
Constructor Details- 
MethodArgumentNotValidExceptionConstructor forMethodArgumentNotValidException.- Parameters:
- parameter- the parameter that failed validation
- bindingResult- the results of the validation
 
- 
MethodArgumentNotValidExceptionConstructor forMethodArgumentNotValidException.- Parameters:
- executable- the executable that failed validation
- bindingResult- the results of the validation
- Since:
- 6.0.5
 
 
- 
- 
Method Details- 
getStatusCodeDescription copied from interface:ErrorResponseReturn the HTTP status code to use for the response.- Specified by:
- getStatusCodein interface- ErrorResponse
 
- 
getBodyDescription copied from interface:ErrorResponseReturn the body for the response, formatted as an RFC 7807ProblemDetailwhosestatusshould match the response status.- Specified by:
- getBodyin interface- ErrorResponse
 
- 
getParameterReturn the method parameter that failed validation.
- 
getMessageDescription copied from class:BindExceptionReturns diagnostic information about the errors held in this object.- Overrides:
- getMessagein class- BindException
 
- 
getDetailMessageArgumentsDescription copied from interface:ErrorResponseReturn arguments to use along with amessage codeto 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:
- getDetailMessageArgumentsin interface- ErrorResponse
 
- 
getDetailMessageArgumentsDescription copied from interface:ErrorResponseVariant ofErrorResponse.getDetailMessageArguments()that uses the givenMessageSourcefor 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 suppliedMessageSourceandLocale.- Specified by:
- getDetailMessageArgumentsin interface- ErrorResponse
- Parameters:
- messageSource- the- MessageSourceto use for the lookup
- locale- the- Localeto use for the lookup
 
- 
resolveErrorMessagesResolve global and field errors to messages with the givenMessageSourceandLocale.- Returns:
- a Map with errors as key and resolved messages as value
- Since:
- 6.0.3
 
- 
errorsToStringListConvert each givenObjectErrorto a String in single quotes, taking either the error's default message, or its error code.- Since:
- 6.0
 
- 
errorsToStringListpublic static List<String> errorsToStringList(List<? extends ObjectError> errors, @Nullable MessageSource source, Locale locale) Variant oferrorsToStringList(List)that uses aMessageSourceto resolve the message code of the error, or fall back on the error's default message.- Since:
- 6.0
 
 
-