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@Validmethod 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.booleanWhether the violations are for a return value.voidCheck 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:MethodValidationResultReturns the set of constraint violations reported during a validation.- Specified by:
getConstraintViolationsin interfaceMethodValidationResult- Overrides:
getConstraintViolationsin classConstraintViolationException- Returns:
- the
SetofConstraintViolations, or an empty Set
-
getAllValidationResults
Description copied from interface:MethodValidationResultReturn all validation results. This includes method parameters with constraints declared on them, as well as@Validmethod parameters with cascaded constraints.- Specified by:
getAllValidationResultsin interfaceMethodValidationResult- See Also:
-
getValueResults
Description copied from interface:MethodValidationResultReturn only validation results for method parameters with constraints declared directly on them. This excludes@Validmethod parameters with cascaded constraints.- Specified by:
getValueResultsin interfaceMethodValidationResult- See Also:
-
getBeanResults
Description copied from interface:MethodValidationResultReturn only validation results for@Validmethod parameters with cascaded constraints. This excludes method parameters with constraints declared directly on them.- Specified by:
getBeanResultsin interfaceMethodValidationResult- See Also:
-
throwIfViolationsPresent
public void throwIfViolationsPresent()Description copied from interface:MethodValidationResultCheck ifMethodValidationResult.getConstraintViolations()is empty, and if not, raiseMethodValidationException.- Specified by:
throwIfViolationsPresentin interfaceMethodValidationResult
-
toString
-