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
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:
  • Constructor Details

    • MethodArgumentNotValidException

      public MethodArgumentNotValidException(org.springframework.core.MethodParameter parameter, org.springframework.validation.BindingResult bindingResult)
      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 7807 ProblemDetail whose status should match the response status.
      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, e.g. "Invalid content type {0}".
      Specified by:
      getDetailMessageArguments in interface ErrorResponse
    • errorsToStringList

      @Deprecated(since="6.1", forRemoval=true) public static List<String> errorsToStringList(List<? extends org.springframework.validation.ObjectError> errors)
      Deprecated, for removal: This API element is subject to removal in a future version.
      in favor of using BindErrorUtils and BindException.getAllErrors(), to be removed in 6.2
      Convert each given ObjectError to a String.
      Since:
      6.0
    • errorsToStringList

      @Deprecated(since="6.1", forRemoval=true) public static List<String> errorsToStringList(List<? extends org.springframework.validation.ObjectError> errors, @Nullable org.springframework.context.MessageSource messageSource, Locale locale)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
      Since:
      6.0
    • resolveErrorMessages

      @Deprecated(since="6.1", forRemoval=true) public Map<org.springframework.validation.ObjectError,String> resolveErrorMessages(org.springframework.context.MessageSource messageSource, Locale locale)
      Deprecated, for removal: This API element is subject to removal in a future version.
      in favor of using BindErrorUtils and BindException.getAllErrors(), to be removed in 6.2
      Resolve global and field errors to messages with the given MessageSource and Locale.
      Returns:
      a Map with errors as keys and resolved messages as values
      Since:
      6.0.3
    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class org.springframework.validation.BindException