Package org.springframework.validation.method

# Class ParameterValidationResult

java.lang.Object
org.springframework.validation.method.ParameterValidationResult

Direct Known Subclasses:
  `ParameterErrors`

public class ParameterValidationResult extends Object
Store and expose the results of method validation for a method parameter.

- Validation errors directly on method parameter values are exposed as a list of `MessageSourceResolvable`s.
- Nested validation errors on an Object method parameter are exposed as `Errors` by the subclass `ParameterErrors`.

When the method parameter is a container such as a `List`, array, or `Map`, then a separate `ParameterValidationResult` is created for each element with errors. In that case, the properties `container`, `containerIndex`, and `containerKey` provide additional context.

Since:
  6.1
Author:
  Rossen Stoyanchev

## Constructor Summary

Constructors
Constructor
Description
`ParameterValidationResult(org.springframework.core.MethodParameter param, Object arg, Collection<? extends MessageSourceResolvable> errors)`
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `ParameterValidationResult(MethodParameter, Object, Collection, Object, Integer, Object, BiFunction)`
`ParameterValidationResult(org.springframework.core.MethodParameter param, Object arg, Collection<? extends MessageSourceResolvable> errors, Object container, Integer index, Object key)`
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `ParameterValidationResult(MethodParameter, Object, Collection, Object, Integer, Object, BiFunction)`
`ParameterValidationResult(org.springframework.core.MethodParameter param, Object arg, Collection<? extends MessageSourceResolvable> errors, Object container, Integer index, Object key, BiFunction<MessageSourceResolvable,Class<?>,Object> sourceLookup)`
Create a `ParameterValidationResult`.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object other)`
`Object`
`getArgument()`
The method argument value that was validated.
`Object`
`getContainer()`
When `@Valid` is declared on a container of elements such as `Collection`, `Map`, `Optional`, and others, this method returns the container of the validated `argument`, while `getContainerIndex()` and `getContainerKey()` provide information about the index or key if applicable.
`Integer`
`getContainerIndex()`
When `@Valid` is declared on an indexed container of elements such as `List` or array, this method returns the index of the validated `argument`.
`Object`
`getContainerKey()`
When `@Valid` is declared on a container of elements referenced by key such as `Map`, this method returns the key of the validated `argument`.
`org.springframework.core.MethodParameter`
`getMethodParameter()`
The method parameter the validation results are for.
`List<MessageSourceResolvable>`
`getResolvableErrors()`
List of `MessageSourceResolvable` representations adapted from the validation errors of the validation library.
`int`
`hashCode()`
`String`
`toString()`
`<T> T`
`unwrap(MessageSourceResolvable error, Class<T> sourceType)`
Unwrap the source behind the given error.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### ParameterValidationResult

public ParameterValidationResult(org.springframework.core.MethodParameter param, @Nullable Object arg, Collection<? extends MessageSourceResolvable> errors, @Nullable Object container, @Nullable Integer index, @Nullable Object key, BiFunction<MessageSourceResolvable,Class<?>,Object> sourceLookup)
Create a `ParameterValidationResult`.

### ParameterValidationResult

@Deprecated(since="6.2", forRemoval=true) public ParameterValidationResult(org.springframework.core.MethodParameter param, @Nullable Object arg, Collection<? extends MessageSourceResolvable> errors, @Nullable Object container, @Nullable Integer index, @Nullable Object key)
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `ParameterValidationResult(MethodParameter, Object, Collection, Object, Integer, Object, BiFunction)`
Create a `ParameterValidationResult`.

### ParameterValidationResult

@Deprecated(since="6.1.3", forRemoval=true) public ParameterValidationResult(org.springframework.core.MethodParameter param, @Nullable Object arg, Collection<? extends MessageSourceResolvable> errors)
Deprecated, for removal: This API element is subject to removal in a future version.
in favor of `ParameterValidationResult(MethodParameter, Object, Collection, Object, Integer, Object, BiFunction)`
Create a `ParameterValidationResult`.

## Method Details

### getMethodParameter

public org.springframework.core.MethodParameter getMethodParameter()
The method parameter the validation results are for.

### getArgument

@Nullable public Object getArgument()
The method argument value that was validated.

### getResolvableErrors

public List<MessageSourceResolvable> getResolvableErrors()
List of `MessageSourceResolvable` representations adapted from the validation errors of the validation library.

- For a constraints directly on a method parameter, error codes are based on the names of the constraint annotation, the object, the method, the parameter, and parameter type, for example, `["Max.myObject#myMethod.myParameter", "Max.myParameter", "Max.int", "Max"]`. Arguments include the parameter itself as a `MessageSourceResolvable`, for example, `["myObject#myMethod.myParameter", "myParameter"]`, followed by actual constraint annotation attributes (i.e. excluding "message", "groups" and "payload") in alphabetical order of attribute names.
- For cascaded constraints via `@Valid` on a bean method parameter, this method returns `field errors` that you can also access more conveniently through methods of the `ParameterErrors` sub-class.

### getContainer

@Nullable public Object getContainer()
When `@Valid` is declared on a container of elements such as `Collection`, `Map`, `Optional`, and others, this method returns the container of the validated `argument`, while `getContainerIndex()` and `getContainerKey()` provide information about the index or key if applicable.

### getContainerIndex

@Nullable public Integer getContainerIndex()
When `@Valid` is declared on an indexed container of elements such as `List` or array, this method returns the index of the validated `argument`.

### getContainerKey

@Nullable public Object getContainerKey()
When `@Valid` is declared on a container of elements referenced by key such as `Map`, this method returns the key of the validated `argument`.

### unwrap

public <T> T unwrap(MessageSourceResolvable error, Class<T> sourceType)
Unwrap the source behind the given error. For Jakarta Bean validation the source is a `ConstraintViolation`.

Parameters:
  `sourceType` - the expected source type
Returns:
  the source object of the given type
Since:
  6.2

### equals

public boolean equals(@Nullable Object other)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`