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
11
votes
2 answers
Making javax validation error message more specific
Sorry if this question has been covered somewhere before. If it has please link me to it, I haven't been able to find a satisfactory answer as yet.
I've been looking around trying to find a way to have the error messages provided by my javax…

Klee
- 2,022
- 3
- 23
- 32
11
votes
1 answer
Json version of XMLElements choice
For a Java code with the following annotation:
@JsonProperty(value="Contact")
@NotNull(message = "ContactUser or CompanyName is required.")
@Valid
@XmlElements(value = {
@XmlElement(name = "ContactUser", type =…

obsessiveCookie
- 1,130
- 2
- 18
- 33
11
votes
1 answer
javax bean validation not working on method parameters
javax validation not working on method parameters.. This is a test code and none of javax validation works on method parameter...
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, params = "action=testAction")
public Test update(
…

surya
- 2,581
- 3
- 22
- 34
11
votes
4 answers
Spring boot, how to use @Valid with List
I am trying to put validation to a Spring Boot project. So I put @NotNull annotation to Entity fields. In controller I check it like this:
@RequestMapping(value="", method = RequestMethod.POST)
public DataResponse add(@RequestBody @Valid Status…

kalahari
- 895
- 5
- 15
- 34
11
votes
2 answers
Implementing custom validation logic for a Spring Boot endpoint using a combination of JSR-303 and Spring's Validator
I'm trying to implement some custom validation logic for a Spring Boot endpoint using a combination of JSR-303 Bean Validation API and Spring's Validator.
Based on the Validator class diagram it appears to be possible to extend one of…

pavel
- 2,964
- 2
- 14
- 14
11
votes
1 answer
Bean validation group sequence not working
I'm using spring 4.1, hibernate validator 5.1.3 for my project. I've been trying to get the GroupSequence to work from last 2 days. I've referred the validation doc, blogs and a few questions posted on stackoverflow.
Please see the below class.…

jay
- 171
- 4
- 13
11
votes
3 answers
Why can't I use Valid parameter along with RequestParam in Spring MVC?
Example:
public String getStudentResult(@RequestParam(value = "regNo", required = true) String regNo, ModelMap model){
How can I use @valid for the regNo parameter here?

sofs1
- 3,834
- 11
- 51
- 89
10
votes
2 answers
Spring MVC Cross-field Validation: Code Smell?
Is this a code smell, or is it the best way to implement cross-field validation in a Spring form?
@FieldRequiredIf.List({
@FieldRequiredIf(ifField="firstHomePhoneNumber", matches={EMPTY, NULL},require ="firstMobilePhoneNumber",elseDisplay =…

PaddyC
- 576
- 7
- 14
10
votes
1 answer
Spring Boot 3.0 package javax.validation does not exist
I'm trying to use a method parameter validation feature supported by Bean Validation 1.1. For instance, the following method triggers the validation of the first parameter, making sure it's valid:
public String generateOtp(@Valid…

Boris
- 22,667
- 16
- 50
- 71
10
votes
1 answer
Validation @ScriptAssert with access to static methods
The JSR303 Bean Validation implementation Hibernate-Validator (4.1.0) provides the org.hibernate.validator.constraints.ScriptAssert annotation.
I get it working for invocation of not static…

Ralph
- 118,862
- 56
- 287
- 383
10
votes
3 answers
Using both JSR-303 and Traditional Bean Validation?
Is it possible to use both JSR-303 bean validation and traditional validation (a single validator class for the type) in Spring? If so, what configuration is required to set this up?
I have tried the instructions on the…

C. Ross
- 31,137
- 42
- 147
- 238
10
votes
3 answers
How to validate an attribute based on another in spring-boot in a clean way?
I am validating REST service request/bean in a spring-boot 2.3.1.RELEASE web application. Currently, I am using Hibernate Validator, though I am open to using any other way for validation.
Say, I have a model Foo, which I receive as a request in a…

Smile
- 3,832
- 3
- 25
- 39
10
votes
1 answer
How to change location of ValidationMessages.properties in Bean Validation
By default, ValidationMessages.properties can be located in root of my classpath. Can I change the location of this file like com.myapp.Anything.properties?

Otávio Garcia
- 1,372
- 1
- 15
- 27
10
votes
2 answers
Bean Validation for @Past or today?
Here's a simple source, stating that this date must be in the past using Bean Validation :
@Past
private Date transactionDate;
Is there any BV annotation for validating that the date must be today or previous day?
Or perhaps I need to extend the…

Bertie
- 17,277
- 45
- 129
- 182
10
votes
4 answers
What setup do I need to do to use JSR-303 annotations with Spring?
I downloaded spring 3 and put it on my classpath but I'm not able to import the @Valid annotation. However, I am able to import other spring 3 annotations (such as @Controller). What Jar is @Valid in and what package?
EDIT: This is a JSR-303…

stevebot
- 23,275
- 29
- 119
- 181