Questions tagged [bean-validation]

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.

Online resources

1913 questions
8
votes
1 answer

How to inject PathVariable id into RequestBody *before* JSR-303 validation is executed?

I'm stuck in an apparently simple problem: I want to perform some custom validation based on the object id in a PUT request. @RequestMapping(value="/{id}", method=RequestMethod.PUT) public ResponseEntity update(@Valid @RequestBody ClientDTO…
Nelio Alves
  • 1,231
  • 13
  • 34
8
votes
0 answers

Does Spring MVC support for JSR-380 (Bean validation 2)?

JSR-380 adds support for validating containers elements (inside collections, optional) by annotating the parameterized type: List<@Email String> emails; Is there any way to get this to work in current versions (e.g. Spring MVC 4.3.8) of Spring MVC…
Andrew May
  • 266
  • 1
  • 8
8
votes
2 answers

How to validate RestTemplate response?

Spring supports annotation based validation at the controller level. (1) Is it necessary to do such validations also at the RestTemplate level for responses from REST calls? If the answer is Yes: (2) Will there be support for that at the…
Jothi
  • 511
  • 1
  • 5
  • 9
8
votes
3 answers

How to use Hibernate Validator to validate date ranges across multiple rows in a table?

I have a custom validator which I use to ensure that some business rules are applied on an entity before it is saved. For example (a hypothetical one), when ProductPrice, defined below, is saved, I validate that the fromDate and endDate for a given…
Mubin
  • 4,192
  • 3
  • 26
  • 45
8
votes
4 answers

JSR-303 validation in Spring controller and getting @JsonProperty name

I do validation with JSR-303 in my Spring app, it works as needed. This is an example: @Column(nullable = false, name = "name") @JsonProperty("customer_name") @NotEmpty @Size(min = 3, max = 32) private String name; And REST API…
jnemecz
  • 3,171
  • 8
  • 41
  • 77
8
votes
5 answers

Adding custom ConstraintValidator for @Future and LocalDate to a Spring Boot project

I have a Spring MVC form for inputting a date, the input gets sent to a Controller and validated via standard Spring MVC validation. Model: public class InvoiceForm { @Future private LocalDate invoicedate; } Controller: public String…
8
votes
1 answer

Custom exception mapping for bean validation on TomEE 7?

Context We use a javax.ws.rs.ext.ExceptionMapper annotated as @javax.ws.rs.ext.Provider to handle all exceptions. Internally this ExceptionMapper is distinguishing between different types of exceptions to determine what information to…
Schroenser
  • 289
  • 1
  • 7
8
votes
2 answers

How to use SpringMVC @Valid to validate fields in POST and only not null fields in PUT

We are creating a RESTful API with SpringMVC and we have a /products end point where POST can be used to create a new product and PUT to update fields. We are also using javax.validation to validate fields. In POST works fine, but in PUT the user…
diogo beato
  • 175
  • 1
  • 7
8
votes
2 answers

Java bean validation: Optional fields annotation

I would like to treat some fields as Optional, if the value is null or blank don't go with the checks of the other annotated constraints. There is some way to achieve it! Reading this tread Java bean validation: Enforce a @Pattern only when the…
salgaf
  • 181
  • 2
  • 7
8
votes
2 answers

Spring Boot JSR303 message code in annotation getting ignored

In my Spring Boot app I have a backing bean where I am using JSR303 validation. In the annotation, I have specified the message code: @NotBlank(message = "{firstname.isnull}") private String firstname; Then in my message.properties I have…
user3137124
  • 515
  • 1
  • 7
  • 13
8
votes
4 answers

Bean Validation Collection of String not Blank

I have a collection of strings, now I want to make sure that not only the collection is not empty but also each string in that collection does not contain a blank input. @NotEmpty public List getDescriptions() // not empty collection …
Vad1mo
  • 5,156
  • 6
  • 36
  • 65
8
votes
4 answers

How to use Java Bean Validators (JSR-303/JSR-349) on elements of an array/list/collection

I'm new to using Java Bean validation (JSR-303/JSR-349/Hibernate Validator), and understand the general concepts. However, I'm not sure how to validate the contents of an composed type vs the type itself. For example: @NotNull private List
Eric B.
  • 23,425
  • 50
  • 169
  • 316
8
votes
4 answers

Bean validation doesn't work with mojarra 2.2.4

I'm trying to use Hibernate Validator 5.0.1 and JSF2.2 but their integration seems to be broken since mojarra version 2.2.3. I've created small app to demonstrate the issue and get exception "javax.servlet.ServletException: Expression Error: Named…
user2928411
  • 83
  • 1
  • 5
8
votes
2 answers

Validate only if the field is not Null

I use JSR303 Spring Validation and I have the following; @Digits(fraction = 0, integer = 15) private String tpMobile; Validation says Must be number between 10-15 digits, but the thing is this field is optional. So when user left it empty also the…
Ravindu
  • 2,408
  • 8
  • 30
  • 46
8
votes
2 answers

Hibernate - Error activating Bean Validation integration

I am trying to set up Hibernate. But when i try to create my Session Factory, with this code: Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new…
jan
  • 3,923
  • 9
  • 38
  • 78