Top Description Fields Constructors Methods
org.springframework.web.bind

public Class MethodArgumentNotValidException

extends BindException
implements ErrorResponse
Class Inheritance
All Implemented Interfaces
org.springframework.web.ErrorResponse
Annotations
@SuppressWarnings:serial
Imports
java.util.List, .Locale, .Map, org.springframework.context.MessageSource, org.springframework.core.MethodParameter, org.springframework.http.HttpStatus, .HttpStatusCode, .ProblemDetail, org.springframework.lang.Nullable, org.springframework.validation.BindException, .BindingResult, .ObjectError, org.springframework.web.ErrorResponse, org.springframework.web.util.BindErrorUtils

Exception to be thrown when validation on an argument annotated with @Valid fails. Extends BindException as of 5.3.
Authors
Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
Since
3.1

Field Summary

Modifier and TypeField and Description
private final ProblemDetail
private final MethodParameter

Constructor Summary

AccessConstructor and Description
public
MethodArgumentNotValidException(MethodParameter
the parameter that failed validation
parameter
,
BindingResult
the results of the validation
bindingResult
)

Constructor for MethodArgumentNotValidException.

Method Summary

Modifier and TypeMethod and Description
public static List<String>
errorsToStringList(List<? extends ObjectError> errors)
Deprecated for removal since 6.1. in favor of using BindErrorUtils and getAllErrors(), to be removed in 6.2

Convert each given ObjectError to a String.

public static List<String>
errorsToStringList(List<? extends ObjectError> errors, MessageSource messageSource, Locale locale)
Deprecated for removal since 6.1. in favor of BindErrorUtils, to be removed in 6.2

Convert each given ObjectError to a String, and use a MessageSource to resolve each error.

public ProblemDetail
getBody()

Implements org.springframework.web.ErrorResponse.getBody.

Return the body for the response, formatted as an RFC 7807 ProblemDetail whose status should match the response status.

public Object[]
getDetailMessageArguments(MessageSource
the MessageSource to use for the lookup
source
,
Locale
the Locale to use for the lookup
locale
)

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Variant of getDetailMessageArguments() that uses the given MessageSource for resolving the message argument values.

public Object[]
getDetailMessageArguments()

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Return arguments to use along with a message code to resolve the problem "detail" for this exception through a MessageSource.

public String
getMessage()

Overrides org.springframework.validation.BindException.getMessage.

Returns diagnostic information about the errors held in this object.

public final MethodParameter
getParameter()

Return the method parameter that failed validation.

public HttpStatusCode
getStatusCode()

Implements org.springframework.web.ErrorResponse.getStatusCode.

Return the HTTP status code to use for the response.

public Map<ObjectError, String>

Returns:

a Map with errors as keys and resolved messages as values
resolveErrorMessages
(MessageSource messageSource, Locale locale)
Deprecated for removal since 6.1. in favor of using BindErrorUtils and getAllErrors(), to be removed in 6.2

Resolve global and field errors to messages with the given MessageSource and Locale.

Inherited from org.springframework.validation.BindException:
addAllErrorsaddErrorequalsfindEditorgetAllErrorsgetBindingResultgetErrorCountgetFieldErrorgetFieldErrorgetFieldErrorCountgetFieldErrorCountgetFieldErrorsgetFieldErrorsgetFieldTypegetFieldValuegetGlobalErrorgetGlobalErrorCountgetGlobalErrorsgetModelgetNestedPathgetObjectNamegetPropertyEditorRegistrygetRawFieldValuegetSuppressedFieldsgetTargethasErrorshasFieldErrorshasFieldErrorshasGlobalErrorshashCodepopNestedPathpushNestedPathrecordFieldValuerecordSuppressedFieldrejectrejectrejectrejectValuerejectValuerejectValueresolveMessageCodesresolveMessageCodessetNestedPath

Field Detail

bodyback to summary
private final ProblemDetail body
parameterback to summary
private final MethodParameter parameter

Constructor Detail

MethodArgumentNotValidExceptionback to summary
public MethodArgumentNotValidException(MethodParameter parameter, BindingResult bindingResult)

Constructor for MethodArgumentNotValidException.

Parameters
parameter:MethodParameter

the parameter that failed validation

bindingResult:BindingResult

the results of the validation

Method Detail

errorsToStringListback to summary
public static List<String> errorsToStringList(List<? extends ObjectError> errors)

Deprecated

for removal since 6.1.

in favor of using BindErrorUtils and getAllErrors(), to be removed in 6.2

Convert each given ObjectError to a String.

Annotations
@Deprecated
since:6.1
forRemoval:true
Since
6.0
errorsToStringListback to summary
public static List<String> errorsToStringList(List<? extends ObjectError> errors, MessageSource messageSource, Locale locale)

Deprecated

for removal since 6.1.

in favor of BindErrorUtils, to be removed in 6.2

Convert each given ObjectError to a String, and use a MessageSource to resolve each error.

Annotations
@Deprecated
since:6.1
forRemoval:true
Since
6.0
getBodyback to summary
public ProblemDetail getBody()

Implements org.springframework.web.ErrorResponse.getBody.

Doc from org.springframework.web.ErrorResponse.getBody.

Return the body for the response, formatted as an RFC 7807 ProblemDetail whose status should match the response status.

Annotations
@Override
getDetailMessageArgumentsback to summary
public Object[] getDetailMessageArguments(MessageSource source, Locale locale)

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Doc from org.springframework.web.ErrorResponse.getDetailMessageArguments.

Variant of getDetailMessageArguments() that uses the given MessageSource for resolving the message argument values.

This is useful for example to expand message codes from validation errors.

The default implementation delegates to getDetailMessageArguments(), ignoring the supplied MessageSource and Locale.

Parameters
source:MessageSource

the MessageSource to use for the lookup

locale:Locale

the Locale to use for the lookup

Annotations
@Override
getDetailMessageArgumentsback to summary
public Object[] getDetailMessageArguments()

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Doc from org.springframework.web.ErrorResponse.getDetailMessageArguments.

Return arguments to use along with a message code to resolve the problem "detail" for this exception through a MessageSource. The arguments are expanded into placeholders of the message value, e.g. "Invalid content type {0}".

Annotations
@Override
getMessageback to summary
public String getMessage()

Overrides org.springframework.validation.BindException.getMessage.

Doc from org.springframework.validation.BindException.getMessage.

Returns diagnostic information about the errors held in this object.

Returns:String

Doc from java.lang.Throwable.getMessage.

the detail message string of this Throwable instance (which may be null).

Annotations
@Override
getParameterback to summary
public final MethodParameter getParameter()

Return the method parameter that failed validation.

getStatusCodeback to summary
public HttpStatusCode getStatusCode()

Implements org.springframework.web.ErrorResponse.getStatusCode.

Doc from org.springframework.web.ErrorResponse.getStatusCode.

Return the HTTP status code to use for the response.

Annotations
@Override
resolveErrorMessagesback to summary
public Map<ObjectError, String> resolveErrorMessages(MessageSource messageSource, Locale locale)

Deprecated

for removal since 6.1.

in favor of using BindErrorUtils and getAllErrors(), to be removed in 6.2

Resolve global and field errors to messages with the given MessageSource and Locale.

Returns:Map<ObjectError, String>

a Map with errors as keys and resolved messages as values

Annotations
@Deprecated
since:6.1
forRemoval:true
Since
6.0.3