-
public interface ConstraintViolation<T>
Describes a constraint violation. This object exposes the constraint violation context as well as the message describing the violation.- Author:
- Emmanuel Bernard
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description ConstraintDescriptor<?>
getConstraintDescriptor()
Returns the constraint metadata reported to fail.Object[]
getExecutableParameters()
Returns anObject[]
representing the constructor or method invocation arguments if theConstraintViolation
is returned after validating the method or constructor parameters.Object
getExecutableReturnValue()
Returns the return value of the constructor or method invocation if theConstraintViolation
is returned after validating the method or constructor return value.Object
getInvalidValue()
Returns the value failing to pass the constraint.Object
getLeafBean()
Returns: 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 constraintnull
when theConstraintViolation
is 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 constraintnull
if it is a constructor parameter or cross-parameter constraint the object the constructor has created if it is a constructor return value constraintString
getMessage()
String
getMessageTemplate()
Path
getPropertyPath()
T
getRootBean()
Returns the root bean being validated.Class<T>
getRootBeanClass()
Returns the class of the root bean being validated.<U> U
unwrap(Class<U> type)
Returns an instance of the specified type allowing access to provider-specific APIs.
-
-
-
Method Detail
-
getMessage
String getMessage()
- Returns:
- the interpolated error message for this constraint violation
-
getMessageTemplate
String getMessageTemplate()
- Returns:
- the non-interpolated error message for this constraint violation
-
getRootBean
T getRootBean()
Returns the root bean being validated. For method validation, returns the object the method is executed on. Returnsnull
when:- the
ConstraintViolation
is returned after callingValidator.validateValue(Class, String, Object, Class[])
- the
ConstraintViolation
is returned after validating a constructor.
- Returns:
- the validated object, the object hosting the validated element or
null
- the
-
getRootBeanClass
Class<T> getRootBeanClass()
Returns 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.- Returns:
- the class of the root bean or of the object hosting the validated element
-
getLeafBean
Object getLeafBean()
Returns:- 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
null
when theConstraintViolation
is 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
null
if it is a constructor parameter or cross-parameter constraint- the object the constructor has created if it is a constructor return value constraint
- Returns:
- the leaf bean
-
getExecutableParameters
Object[] getExecutableParameters()
Returns anObject[]
representing the constructor or method invocation arguments if theConstraintViolation
is returned after validating the method or constructor parameters. Returnsnull
otherwise.- Returns:
- parameters of the method or constructor invocation or
null
- Since:
- 1.1
-
getExecutableReturnValue
Object getExecutableReturnValue()
Returns the return value of the constructor or method invocation if theConstraintViolation
is returned after validating the method or constructor return value. Returnsnull
if the method has no return value. Returnsnull
otherwise.- Returns:
- the method or constructor return value or
null
- Since:
- 1.1
-
getPropertyPath
Path getPropertyPath()
- Returns:
- the property path to the value from
rootBean
-
getInvalidValue
Object getInvalidValue()
Returns the value failing to pass the constraint. For cross-parameter constraints, anObject[]
representing the method invocation arguments is returned.- Returns:
- the value failing to pass the constraint
-
getConstraintDescriptor
ConstraintDescriptor<?> getConstraintDescriptor()
Returns the constraint metadata reported to fail. The returned instance is immutable.- Returns:
- constraint metadata
-
unwrap
<U> U unwrap(Class<U> type)
Returns an instance of the specified type allowing access to provider-specific APIs. If the Bean Validation provider implementation does not support the specified class,ValidationException
is thrown.- Parameters:
type
- the class of the object to be returned- Returns:
- an instance of the specified class
- Throws:
ValidationException
- if the provider does not support the call- Since:
- 1.1
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 18:30:27 Cette version de la page est en cache (à la date du 21/08/2025 18:30:27) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/validation/constraintviolation.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.