-
public interface Validator
Validates bean instances. Implementations of this interface must be thread-safe.- Author:
- Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description ExecutableValidator
forExecutables()
Returns the contract for validating parameters and return values of methods and constructors.BeanDescriptor
getConstraintsForClass(Class<?> clazz)
Returns the descriptor object describing bean constraints.<T> T
unwrap(Class<T> type)
Returns an instance of the specified type allowing access to provider-specific APIs.<T> Set<ConstraintViolation<T>>
validate(T object, Class<?>... groups)
Validates all constraints onobject
.<T> Set<ConstraintViolation<T>>
validateProperty(T object, String propertyName, Class<?>... groups)
Validates all constraints placed on the property ofobject
namedpropertyName
.<T> Set<ConstraintViolation<T>>
validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
Validates all constraints placed on the property namedpropertyName
of the classbeanType
would the property value bevalue
.
-
-
-
Method Detail
-
validate
<T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups)
Validates all constraints onobject
.- Parameters:
object
- object to validategroups
- the group or list of groups targeted for validation (defaults toDefault
)- Returns:
- constraint violations or an empty set if none
- Throws:
IllegalArgumentException
- if object isnull
or ifnull
is passed to the varargs groupsValidationException
- if a non recoverable error happens during the validation process
-
validateProperty
<T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups)
Validates all constraints placed on the property ofobject
namedpropertyName
.- Parameters:
object
- object to validatepropertyName
- property to validate (i.e. field and getter constraints)groups
- the group or list of groups targeted for validation (defaults toDefault
)- Returns:
- constraint violations or an empty set if none
- Throws:
IllegalArgumentException
- ifobject
isnull
, ifpropertyName
isnull
, empty or not a valid object property or ifnull
is passed to the varargs groupsValidationException
- if a non recoverable error happens during the validation process
-
validateValue
<T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
Validates all constraints placed on the property namedpropertyName
of the classbeanType
would the property value bevalue
.ConstraintViolation
objects returnnull
forConstraintViolation.getRootBean()
andConstraintViolation.getLeafBean()
.- Parameters:
beanType
- the bean typepropertyName
- property to validatevalue
- property value to validategroups
- the group or list of groups targeted for validation (defaults toDefault
).- Returns:
- constraint violations or an empty set if none
- Throws:
IllegalArgumentException
- ifbeanType
isnull
, ifpropertyName
isnull
, empty or not a valid object property or ifnull
is passed to the varargs groupsValidationException
- if a non recoverable error happens during the validation process
-
getConstraintsForClass
BeanDescriptor getConstraintsForClass(Class<?> clazz)
Returns the descriptor object describing bean constraints. The returned object (and associated objects includingConstraintDescriptor
s) are immutable.- Parameters:
clazz
- class or interface type evaluated- Returns:
- the bean descriptor for the specified class
- Throws:
IllegalArgumentException
- if clazz isnull
ValidationException
- if a non recoverable error happens during the metadata discovery or if some constraints are invalid.
-
unwrap
<T> T unwrap(Class<T> 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
-
forExecutables
ExecutableValidator forExecutables()
Returns the contract for validating parameters and return values of methods and constructors.- Returns:
- contract for method and constructor validation
- Since:
- 1.1
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/validation/validator.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.