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
41
votes
10 answers
Spring MVC - @Valid on list of beans in REST service
In a Spring MVC REST service (json), I have a controller method like this one :
@RequestMapping(method = RequestMethod.POST, value = { "/doesntmatter" })
@ResponseBody
public List<...> myMethod(@Valid @RequestBody List request,…

Raphaël Lemaire
- 1,269
- 1
- 13
- 23
40
votes
4 answers
JSR 303 Bean Validation - Why on getter and not setter?
I don't understand why JSR 303 (bean validation) is for the getter methods and not setter? Isn't it more logical to put it under setter method since that is the entry point into a field and validation should be checked prior to that?

yapkm01
- 3,590
- 7
- 37
- 62
40
votes
3 answers
Javax validation on nested objects - not working
In my Spring Boot project I have two DTO's which I'm trying to validate, LocationDto and BuildingDto. The LocationDto has a nested object of type BuildingDto.
These are my DTO's:
LocationDto
public class LocationDto {
@NotNull(groups = {…

Daniel Castillo
- 625
- 2
- 8
- 12
40
votes
1 answer
Jersey/JAX-RS : How to cascade beans-validation recursively with @Valid automatically?
I am validating my POJOs in a REST resource endpoint in Jersey:
public class Resource {
@POST
public Response post(@NotNull @Valid final POJO pojo) {
...
}
}
public class POJO {
@NotNull
protected final String name;
…
user4460845
35
votes
2 answers
How to manually trigger Spring validation?
The annotated Spring validation on fields of a POJO works when it is created from JSON request body. However, when I create the same object manually (using setters) and want to trigger validation, I'm not sure how to do that.
Here is the…

Srini K
- 3,315
- 10
- 37
- 47
34
votes
1 answer
Can you change an annotation message at run time?
I'm trying to include a dynamic message in my annotation that changes the main body of the text based on the values that are found in the other variables that are passed to it. I set a default message, but when a certain indicator is set, I want to…

coder
- 6,111
- 19
- 54
- 73
34
votes
3 answers
JSR-303 validation groups define a default group
I have a bean that has a lot of fields annotated with JSR-303 validation annotations. There is a new requirement now that one of the fields is mandatory, but only in certain conditions.
I looked around and have found what I needed, validation…

Geoffrey De Vylder
- 3,963
- 7
- 36
- 56
33
votes
9 answers
Validate positive integers
I want to allow only positive integers for number fields including zero. How can I define this validation using JSR 303 ?
I tried
@Min(value=0 message = "msg1") - But it allows float values like 1.2.
@Digits(fraction = 0, integer = 10, message…

Ajinkya
- 22,324
- 33
- 110
- 161
33
votes
4 answers
javax.servlet.ServletException: HV000030: No validator could be found for type: java.lang.Integer
I have to update information in my database.
FacadePatient.java class code:
public Patient update(Patient p) {
Patient pat = em.find(Patient.class, p.getPatientId());
p.setPatientPhone(pat.getPatientPhone());
…

Héla
- 359
- 1
- 3
- 6
32
votes
4 answers
Spring Boot can't autowire @ConfigurationProperties
Here is my FileStorageProperties class:
@Data
@ConfigurationProperties(prefix = "file")
public class FileStorageProperties {
private String uploadDir;
}
This gives me saying : not registered via @enableconfigurationproperties or marked…

Maifee Ul Asad
- 3,992
- 6
- 38
- 86
32
votes
2 answers
Customize spring validation error
I want customize the spring validation error for
@NotNull
@Length(max = 80)
private String email;
but I'm unable to do it.
What are the step to follow?

Roberto de Santis
- 868
- 5
- 15
- 26
32
votes
6 answers
javax.validation.ValidationException: Unable to find default provider
I am currently working on Spring MVC web app and trying to hook up validation using the @Valid annotation. When I fire up the application I'm getting the following exception:
javax.validation.ValidationException: Unable to find a default provider
I…

Caps
- 1,493
- 1
- 16
- 24
31
votes
8 answers
Get field name when javax.validation.ConstraintViolationException is thrown
When the PathVariable 'name' doesn't pass validation a javax.validation.ConstraintViolationException is thrown. Is there a way to retrieve the parameter name in the thrown…

Josh
- 371
- 1
- 4
- 12
31
votes
1 answer
Bean Validation Groups - Understanding it correctly
I am trying to understand the Groups in Bean validation.
So for instance if I have a bean and I want only certain field validated for certain cases, I should group them?
@NotNull (groups=MyClassX.class)
@Min (groups=MyClassA.class) // 1
…

Kevin Rave
- 13,876
- 35
- 109
- 173
29
votes
4 answers
Bean Validation @NotNull, @NotBlank and @NotEmpty does not work in JSF+Tomcat
I am using Hibernate Validation annotations in my JSF managed bean. When I use @NotNull, @NotBlank or @NotEmpty they doesn't seem to be triggered in any way.
@NotBlank(message = "{name.required}")
public String name;
View:

Mahmoud Saleh
- 33,303
- 119
- 337
- 498