Class ConstraintViolationImpl<T>
java.lang.Object
org.hibernate.validator.internal.engine.ConstraintViolationImpl<T>
- All Implemented Interfaces:
ConstraintViolation<T>,Serializable,HibernateConstraintViolation<T>
public class ConstraintViolationImpl<T>
extends Object
implements HibernateConstraintViolation<T>, Serializable
- Author:
- Emmanuel Bernard, Hardy Ferentschik
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanIMPORTANT - some behaviour of Validator depends on the correct implementation of this equals method!static <T> ConstraintViolation<T>forBeanValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object dynamicPayload) static <T> ConstraintViolation<T>forParameterValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object[] executableParameters, Object dynamicPayload) static <T> ConstraintViolation<T>forReturnValueValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object executableReturnValue, Object dynamicPayload) final ConstraintDescriptor<?>Returns the constraint metadata reported to fail.<C> CgetDynamicPayload(Class<C> type) Object[]Returns anObject[]representing the constructor or method invocation arguments if theConstraintViolationis returned after validating the method or constructor parameters.Returns the return value of the constructor or method invocation if theConstraintViolationis returned after validating the method or constructor return value.final ObjectReturns the value failing to pass the constraint.final ObjectReturns: the bean instance the constraint is applied on if it is a bean constraint the bean instance hosting the property the constraint is applied on if it is a property constraint or a container element constraint hosted on a propertynullwhen theConstraintViolationis returned after callingValidator.validateValue(Class, String, Object, Class[])the object the method is executed on if it is a method parameter, cross-parameter or return value constraint or a container element constraint hosted on a method parameter or return valuenullif it is a constructor parameter or cross-parameter constraint or a container element constraint hosted on a constructor parameter the object the constructor has created if it is a constructor return value constraintfinal Stringfinal Stringfinal Pathfinal TReturns the root bean being validated.Returns the class of the root bean being validated.inthashCode()toString()<C> CReturns an instance of the specified type allowing access to provider-specific APIs.
-
Method Details
-
forBeanValidation
public static <T> ConstraintViolation<T> forBeanValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object dynamicPayload) -
forParameterValidation
public static <T> ConstraintViolation<T> forParameterValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object[] executableParameters, Object dynamicPayload) -
forReturnValueValidation
public static <T> ConstraintViolation<T> forReturnValueValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object executableReturnValue, Object dynamicPayload) -
getMessage
- Specified by:
getMessagein interfaceConstraintViolation<T>- Returns:
- the interpolated error message for this constraint violation
-
getMessageTemplate
- Specified by:
getMessageTemplatein interfaceConstraintViolation<T>- Returns:
- the non-interpolated error message for this constraint violation
-
getMessageParameters
- Returns:
- the message parameters added using
HibernateConstraintValidatorContext.addMessageParameter(String, Object)
-
getExpressionVariables
- Returns:
- the expression variables added using
HibernateConstraintValidatorContext.addExpressionVariable(String, Object)
-
getRootBean
Description copied from interface:ConstraintViolationReturns the root bean being validated. For method validation, returns the object the method is executed on.Returns
nullwhen:- the
ConstraintViolationis returned after callingValidator.validateValue(Class, String, Object, Class[]) - the
ConstraintViolationis returned after validating a constructor.
- Specified by:
getRootBeanin interfaceConstraintViolation<T>- Returns:
- the validated object, the object hosting the validated element or
null
- the
-
getRootBeanClass
Description copied from interface:ConstraintViolationReturns the class of the root bean being validated. For method validation, this is the object class the method is executed on. For constructor validation, this is the class the constructor is declared on.- Specified by:
getRootBeanClassin interfaceConstraintViolation<T>- Returns:
- the class of the root bean or of the object hosting the validated element
-
getLeafBean
Description copied from interface:ConstraintViolationReturns:- the bean instance the constraint is applied on if it is a bean constraint
- the bean instance hosting the property the constraint is applied on if it is a property constraint or a container element constraint hosted on a property
nullwhen theConstraintViolationis returned after callingValidator.validateValue(Class, String, Object, Class[])- the object the method is executed on if it is a method parameter, cross-parameter or return value constraint or a container element constraint hosted on a method parameter or return value
nullif it is a constructor parameter or cross-parameter constraint or a container element constraint hosted on a constructor parameter- the object the constructor has created if it is a constructor return value constraint
- Specified by:
getLeafBeanin interfaceConstraintViolation<T>- Returns:
- the leaf bean
-
getInvalidValue
Description copied from interface:ConstraintViolationReturns the value failing to pass the constraint. For cross-parameter constraints, anObject[]representing the method invocation arguments is returned.- Specified by:
getInvalidValuein interfaceConstraintViolation<T>- Returns:
- the value failing to pass the constraint
-
getPropertyPath
- Specified by:
getPropertyPathin interfaceConstraintViolation<T>- Returns:
- the property path to the value from
rootBean
-
getConstraintDescriptor
Description copied from interface:ConstraintViolationReturns the constraint metadata reported to fail. The returned instance is immutable.- Specified by:
getConstraintDescriptorin interfaceConstraintViolation<T>- Returns:
- constraint metadata
-
unwrap
Description copied from interface:ConstraintViolationReturns an instance of the specified type allowing access to provider-specific APIs. If the Jakarta Bean Validation provider implementation does not support the specified class,ValidationExceptionis thrown.- Specified by:
unwrapin interfaceConstraintViolation<T>- Type Parameters:
C- the type of the object to be returned- Parameters:
type- the class of the object to be returned- Returns:
- an instance of the specified class
-
getExecutableParameters
Description copied from interface:ConstraintViolationReturns anObject[]representing the constructor or method invocation arguments if theConstraintViolationis returned after validating the method or constructor parameters. Returnsnullotherwise.- Specified by:
getExecutableParametersin interfaceConstraintViolation<T>- Returns:
- parameters of the method or constructor invocation or
null
-
getExecutableReturnValue
Description copied from interface:ConstraintViolationReturns the return value of the constructor or method invocation if theConstraintViolationis returned after validating the method or constructor return value.Returns
nullif the method has no return value. Returnsnullotherwise.- Specified by:
getExecutableReturnValuein interfaceConstraintViolation<T>- Returns:
- the method or constructor return value or
null
-
getDynamicPayload
- Specified by:
getDynamicPayloadin interfaceHibernateConstraintViolation<T>- Parameters:
type- The type of payload to retrieve- Returns:
- an instance of the specified type set by the user via
HibernateConstraintValidatorContext.withDynamicPayload(Object)ornullif no constraint payload if the given type has been set.
-
equals
IMPORTANT - some behaviour of Validator depends on the correct implementation of this equals method! (HF)messageParameters,expressionVariablesanddynamicPayloadare not taken into account for equality. These variables solely enrich the actual Constraint Violation with additional information e.g how we actually got to this CV. -
hashCode
public int hashCode() -
toString
-