Bean Validation, previously commonly called just "JSR-303", is an annotation based validation framework for javabean properties and parameters of arbitrary methods. Hibernate Validator is the reference implementation and the most widely used one.
Questions tagged [bean-validation]
1913 questions
29
votes
2 answers
Why do bean validation Min/Max constraints not support the double type?
Could somebody please explain to me why the JPA supports the double type as a field type, but the bean validation constaints in javax.validation.constraints (i.e. @Min/@Max) do not support it?
I know documentation says this is due to rounding…

Manuel Leuenberger
- 2,327
- 3
- 21
- 27
29
votes
2 answers
@Pattern for alphanumeric string - Bean validation
I have a variable name in a bean. I want to add @Pattern validation to accept only alphanumeric.
Currently, I have this one.
@NotNull
@Pattern(regexp = "{A-Za-z0-9}*")
String name;
But the error is Invalid regular expression.
I tried…

Kevin Rave
- 13,876
- 35
- 109
- 173
29
votes
1 answer
Adding error message to Spring 3 DataBinder for custom object fields
I'm trying to manually add an individual email error message to my model but nothing is displaying in the view.
I think it may be how I'm creating or attached the ObjectError to the BindingResult.
I'm adding the error inside the catch.
Here is the…

Thomas Buckley
- 5,836
- 19
- 62
- 110
28
votes
2 answers
What is point of constraint validation @Null?
I was checking list of available constraints in javax.validation package and I noticed that there is an annotation @Null which force the field to be null.
I do not understand what is point of adding it to my field if I already know it should be…

Arashsoft
- 2,749
- 5
- 35
- 58
28
votes
5 answers
How do I import javax.validation into my Java SE project?
I'm trying to add constraints checking, as described here How to specify the cardinality of a @OneToMany in EclipseLink/JPA

simpatico
- 10,709
- 20
- 81
- 126
27
votes
3 answers
java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName
JDK: 1.8.0_131
Tomcat: 8.0.27.0
Hibernate Validator: 6.0.7.Final + all the dependencies downloaded from: Hibernate Validator 6
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public…

asabd
- 299
- 1
- 5
- 9
26
votes
3 answers
No validator could be found for constraint 'javax.validation.constraints.Size'
I have the following error
javax.validation.UnexpectedTypeException: HV000030: No validator could
be found for constraint 'javax.validation.constraints.Size' validating
type 'java.lang.Integer'. Check configuration for 'discounted'
My code…

Lucas. D
- 445
- 1
- 7
- 16
26
votes
4 answers
How to I get Spring-Data-MongoDB to validate my objects?
I have a very simple Spring Boot application that uses Spring-Data-Mongodb
All I want to do is set a JSR-303 validation rule that says the object I'm saving must have a username. I read that JSR-303 was added to spring-data-mongodb in version 1.1 so…

Zac Tolley
- 2,340
- 4
- 19
- 22
26
votes
4 answers
Inject Service in ConstraintValidator [Bean Validator - JSR 303] Spring
Good Afternoon,
I am having problem to inject a service within a Bean Validator (JSR 303). I would be performing a validation, but I need to validate this record in my database;
When I use my service it throws NullPointerException;
Exception:…

Tiarê Balbi
- 1,480
- 1
- 23
- 32
25
votes
3 answers
JPA - No validator could be found for type: enum
I have an entity class which uses an enum type for one of the properties, and I am getting the following exception when I try to persist the entity:
javax.validation.UnexpectedTypeException: No validator could be found for type:…

GreenSaguaro
- 2,968
- 2
- 22
- 41
25
votes
3 answers
bean validation not working with kotlin (JSR 380)
so first of all i could not think of a better title for this question so i'm open for changes.
I am trying to validate a bean using the bean validation mechanism (JSR-380) with spring boot.
So i got a controller like…

Tommy Schmidt
- 1,224
- 1
- 16
- 30
25
votes
1 answer
Spring validation for list of accepted string values
Is there a validation annotation for Spring that will do something like:
@ValidString({"US", "GB", "CA"})
final String country;
and validate that the string is one of the supported values in the array?

lmo523
- 459
- 1
- 7
- 18
25
votes
5 answers
How to test a Validator which implements ConstraintValidator in java?
I have an "AllowedValuesValidator.java" class:
public class AllowedValuesValidator implements ConstraintValidator {
String[] values;
String defaultValue;
@Override
public void initialize(AllowedValues…

goe
- 1,153
- 2
- 12
- 24
23
votes
3 answers
Empty validatedBy in @Constraint
I noticed that all built-in constraints have an empty value for the validatedBy parameter in @Constraint. i.e. @Constraint(validatedBy = {})
First, why are they allowed to have an empty value for validatedBy? I thought you can leave it blank only…

Tom Tucker
- 11,676
- 22
- 89
- 130
23
votes
5 answers
Java Bean Validation (JSR303) constraints involving relationship between several bean properties
Say I have the following simple java bean:
class MyBean {
private Date startDate;
private Date endDate;
//setter, getters etc...
}
Is there a mechanism in JSR 303 to create a custom validator that validates the constraint that startDate…

Hedenius Access
- 567
- 2
- 7
- 11