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`, `org.springframework.validation.BindingResult`, `org.springframework.validation.Errors`, `ErrorResponse`

public class MethodArgumentNotValidException extends org.springframework.validation.BindException implements ErrorResponse
`BindException` to be thrown when validation on an argument annotated with `@Valid` fails.

Since:
  3.1
Author:
  Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse

`ErrorResponse.Builder, ErrorResponse.Interceptor`

## 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

Constructors
Constructor
Description
`MethodArgumentNotValidException(org.springframework.core.MethodParameter parameter, org.springframework.validation.BindingResult bindingResult)`
Constructor for `MethodArgumentNotValidException`.

## Method Summary

Modifier and Type
Method
Description
`ProblemDetail`
`getBody()`
Return the body for the response, formatted as an RFC 9457 `ProblemDetail` whose `status` should match the response status.
`Object[]`
`getDetailMessageArguments()`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`.
`Object[]`
`getDetailMessageArguments(org.springframework.context.MessageSource source, Locale locale)`
Variant of `ErrorResponse.getDetailMessageArguments()` that uses the given `MessageSource` for resolving the message argument values.
`String`
`getMessage()`
`final org.springframework.core.MethodParameter`
`getParameter()`
Return the method parameter that failed validation.
`HttpStatusCode`
`getStatusCode()`
Return the HTTP status code to use for the response.

### Methods 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`

### Methods inherited from interface org.springframework.validation.Errors

`failOnError, toString`

## Constructor Details

### MethodArgumentNotValidException

public MethodArgumentNotValidException(org.springframework.core.MethodParameter parameter, org.springframework.validation.BindingResult bindingResult)
Constructor for `MethodArgumentNotValidException`.

Parameters:
  `parameter` - the parameter that failed validation
  `bindingResult` - the results of the validation

## Method Details

### getParameter

public final org.springframework.core.MethodParameter getParameter()
Return the method parameter that failed validation.

### getStatusCode

public HttpStatusCode getStatusCode()
Description copied from interface: `ErrorResponse`
Return the HTTP status code to use for the response.

Specified by:
  `getStatusCode` in interface `ErrorResponse`

### getBody

public ProblemDetail getBody()
Description copied from interface: `ErrorResponse`
Return the body for the response, formatted as an RFC 9457 `ProblemDetail` whose `status` should match the response status.

Note: The returned `ProblemDetail` may be updated before the response is rendered, for example, via `ErrorResponse.updateAndGetBody(MessageSource, Locale)`. Therefore, implementing methods should use an instance field, and should not re-create the `ProblemDetail` on every call, nor use a static variable.

Specified by:
  `getBody` in interface `ErrorResponse`

### getDetailMessageArguments

public Object[] getDetailMessageArguments(org.springframework.context.MessageSource source, Locale locale)
Description copied from interface: `ErrorResponse`
Variant of `ErrorResponse.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 `ErrorResponse.getDetailMessageArguments()`, ignoring the supplied `MessageSource` and `Locale`.

Specified by:
  `getDetailMessageArguments` in interface `ErrorResponse`
Parameters:
  `source` - the `MessageSource` to use for the lookup
  `locale` - the `Locale` to use for the lookup

### getDetailMessageArguments

public Object[] getDetailMessageArguments()
Description copied from interface: `ErrorResponse`
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, for example, "Invalid content type {0}".

Specified by:
  `getDetailMessageArguments` in interface `ErrorResponse`

### getMessage

public String getMessage()

Overrides:
  `getMessage` in class `org.springframework.validation.BindException`