Package dev.orne.beans
Class BeanValidationUtils
java.lang.Object
dev.orne.beans.BeanValidationUtils
Utility class for bean validations.
- Since:
- 0.1
- Version:
- 1.0, 2020-05
- Author:
- (w) Iker Hernaez
-
Method Summary
Modifier and TypeMethodDescriptionstatic javax.validation.Validator
Returns the sharedValidator
used to validate beans.static boolean
Validates if the specified bean is valid for the specified validation groups.static boolean
isValidBeanIdentity
(@NotNull Object obj) Validates if the specified bean has a valid, non null, identity.static boolean
isValidBeanReference
(@NotNull Object obj) Validates if the specified bean is a valid bean reference.static void
setValidator
(@NotNull javax.validation.Validator validator) Sets the sharedValidator
used to validate beans.static <T> @NotNull Set<javax.validation.ConstraintViolation<T>>
Validates the specified bean for the specified validation groups.
-
Method Details
-
getValidator
public static javax.validation.Validator getValidator()Returns the sharedValidator
used to validate beans.- Returns:
- The shared
Validator
used to validate beans
-
setValidator
public static void setValidator(@NotNull @NotNull javax.validation.Validator validator) Sets the sharedValidator
used to validate beans.- Parameters:
validator
- The sharedValidator
used to validate beans
-
isValid
Validates if the specified bean is valid for the specified validation groups.- Parameters:
obj
- The bean to validategroups
- The group or list of groups targeted for validation (defaults to Default)- Returns:
- If the object is valid for the specified groups
- Throws:
IllegalArgumentException
- if object isnull
or ifnull
is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
isValidBeanIdentity
Validates if the specified bean has a valid, non null, identity.- Parameters:
obj
- The bean to validate- Returns:
- If the bean has a valid identity
- Throws:
IllegalArgumentException
- if bean isnull
javax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
isValidBeanReference
Validates if the specified bean is a valid bean reference.- Parameters:
obj
- The bean to validate- Returns:
- If the bean is a valid bean reference
- Throws:
IllegalArgumentException
- if bean isnull
javax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
validate
@NotNull public static <T> @NotNull Set<javax.validation.ConstraintViolation<T>> validate(@NotNull T obj, @NotNull @NotNull Class<?>... groups) Validates the specified bean for the specified validation groups.- Type Parameters:
T
- The type of bean to validate- Parameters:
obj
- The bean to validategroups
- The group or list of groups targeted for validation (defaults to Default)- Returns:
- The constraint violations or an empty set if none
- Throws:
IllegalArgumentException
- if object isnull
or ifnull
is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-