Class MethodValidationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
jakarta.validation.ValidationException
jakarta.validation.ConstraintViolationException
org.springframework.validation.beanvalidation.MethodValidationException
- All Implemented Interfaces:
Serializable
,MethodValidationResult
public class MethodValidationException
extends ConstraintViolationException
implements MethodValidationResult
Extension of
ConstraintViolationException
that implements
MethodValidationResult
exposing an additional list of
ParameterValidationResult
that represents violations adapted to
MessageSourceResolvable
and grouped by
method parameter.- Since:
- 6.1
- Author:
- Rossen Stoyanchev
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMethodValidationException
(Object target, Method method, Set<? extends ConstraintViolation<?>> violations, List<ParameterValidationResult> validationResults, boolean forReturnValue) -
Method Summary
Modifier and TypeMethodDescriptionReturn all validation results.Return only validation results for@Valid
method parameters with cascaded constraints.Returns the set of constraint violations reported during a validation.Return the method to which validation was applied.Return the target of the method invocation to which validation was applied.Return only validation results for method parameters with constraints declared directly on them.boolean
Whether the violations are for a return value.void
Check ifMethodValidationResult.getConstraintViolations()
is empty, and if not, raiseMethodValidationException
.toString()
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Constructor Details
-
MethodValidationException
public MethodValidationException(Object target, Method method, Set<? extends ConstraintViolation<?>> violations, List<ParameterValidationResult> validationResults, boolean forReturnValue)
-
-
Method Details
-
getTarget
Return the target of the method invocation to which validation was applied. -
getMethod
Return the method to which validation was applied. -
isForReturnValue
public boolean isForReturnValue()Whether the violations are for a return value. If true the violations are from validating a return value. If false the violations are from validating method arguments. -
getConstraintViolations
Description copied from interface:MethodValidationResult
Returns the set of constraint violations reported during a validation.- Specified by:
getConstraintViolations
in interfaceMethodValidationResult
- Overrides:
getConstraintViolations
in classConstraintViolationException
- Returns:
- the
Set
ofConstraintViolation
s, or an empty Set
-
getAllValidationResults
Description copied from interface:MethodValidationResult
Return all validation results. This includes method parameters with constraints declared on them, as well as@Valid
method parameters with cascaded constraints.- Specified by:
getAllValidationResults
in interfaceMethodValidationResult
- See Also:
-
getValueResults
Description copied from interface:MethodValidationResult
Return only validation results for method parameters with constraints declared directly on them. This excludes@Valid
method parameters with cascaded constraints.- Specified by:
getValueResults
in interfaceMethodValidationResult
- See Also:
-
getBeanResults
Description copied from interface:MethodValidationResult
Return only validation results for@Valid
method parameters with cascaded constraints. This excludes method parameters with constraints declared directly on them.- Specified by:
getBeanResults
in interfaceMethodValidationResult
- See Also:
-
throwIfViolationsPresent
public void throwIfViolationsPresent()Description copied from interface:MethodValidationResult
Check ifMethodValidationResult.getConstraintViolations()
is empty, and if not, raiseMethodValidationException
.- Specified by:
throwIfViolationsPresent
in interfaceMethodValidationResult
-
toString
-