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
13
votes
3 answers

How can I support JSR-303 validation and Jackson JSON mapping together effectively?

When building a RESTful web service using Spring MVC, I feel I've encountered a tricky situation when trying to combine Jackson JSON deserialization and JSR-303 bean validation. One of the neat things about JSR-303 validation is that one can return…
DrewEaster
  • 3,316
  • 3
  • 35
  • 39
13
votes
4 answers

Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event: 'prePersist'

I created an EJB Session facade in my Netbeans 7 for saving my entity. I have a manytoone mapping between my Insurance and RatePlan Class. public class Insurance{ @ManyToOne(optional=false) @JoinColumn(name="PLAN_ID") private RatePlan…
Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
13
votes
3 answers

How to use @Pattern on non-mandatory fields JSR 303

How can i use @Pattern constraint on non-mandatory form fields ? @Pattern(regexp="...") private String something; as soon as i submit my form, i get validation error as expected but the user may leave the field empty, since this is not a mandatory…
Erhan Bagdemir
  • 5,231
  • 6
  • 34
  • 40
13
votes
1 answer

JSR-303 Type Checking Before Binding

model.... @Digits(integer=5, fraction=0, message="The value must be numeric and less than five digits") private int value; beans file.... controller.... @RequestMapping(value = "/admin/save.htm", method = {…
oreoshake
  • 4,712
  • 1
  • 31
  • 38
13
votes
0 answers

@NotNull annotation is not checking null queryparameter in Jersey REST resource

I am trying to use javax.validation.validation-api for validating @QueryParam parameters. I have followed steps as below: Added dependency: javax.validation validation-api
Bruso
  • 803
  • 3
  • 12
  • 25
13
votes
2 answers

JSR303 custom validators being called twice

I am creating a website using Spring MVC and for persistence I am using Spring Data JPA with Hibernate 4 as my JPA provider. Validation is being handled at present with Hibernate Validator. I have a problem whereby my validators are being called…
F Sohail
  • 153
  • 1
  • 6
13
votes
2 answers

Building Dynamic ConstraintViolation Error Messages

I've written a validation annotation implemented by a custom ConstraintValidator. I also want to generate very specific ConstraintViolation objects that use values computed during the validation process during message interpolation. public class…
Misha
  • 909
  • 1
  • 7
  • 15
13
votes
7 answers

Validating double and float values using Hibernate Validator - bean validation

I'm looking for a way to validate a java.lang.Double field in the Spring command bean for its maximum and minimum values (a value must lie between a given range of values) like, public final class WeightBean { …
Tiny
  • 27,221
  • 105
  • 339
  • 599
12
votes
3 answers

can I override a jsr-303 validation annotation

I have a test like below: public class TestSizeAnnotation { public static void main(String[] args) { System.out.println(Validation.buildDefaultValidatorFactory().getValidator().validate(new C())); } public static class P …
oshai
  • 14,865
  • 26
  • 84
  • 140
12
votes
4 answers

JSF 2.0: How to skip JSR-303 bean validation?

How to skip JSR-303 Bean validation with JSF, when a button is clicked? A bit lengthy question to explain a few approaches... Consider a list in a form:
Tuukka Mustonen
  • 4,722
  • 9
  • 49
  • 79
12
votes
3 answers

Spring webflux bean validation not working

I am trying to use bean validation in Webflux. This is what I have so far: @PostMapping("contact") fun create(@RequestBody @Valid contact: Mono) : Mono { return contact.flatMap { contactRepository.save(it) } …
Jan Wytze
  • 3,307
  • 5
  • 31
  • 51
12
votes
1 answer

Using a custom ResourceBundle with Hibernate Validator

I'm trying to set up a custom message source for Hibernate Validator 4.1 through Spring 3.0. I've set up the necessary configuration:
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
12
votes
3 answers

GWT JSR 303 client validation

I'm developing a GWT application with a Spring backend that uses JSR 303 validation. The application can go offline and use the browser HTML5/Gears database instead. What is the best way to implement the client validation? So far I have found…
Javier Ferrero
  • 8,741
  • 8
  • 45
  • 50
12
votes
3 answers

How to avoid cross dependency between layers because of @Constraint validatedBy?

In our project we have Service and DAO layers in separate Maven modules. Service module depends on DAO module and works with it's entities. The problem is that we can't put custom jsr 303 constraint which uses some services from service layer in DAO…
calavera.info
  • 1,170
  • 2
  • 15
  • 30
11
votes
1 answer

How can I use the useBeanValidation option when generating code in Swagger?

Swagger's code generation for a Spring server has an option called useBeanValidation, but I can't figure out how to use it. I couldn't find any documentation telling me which validations it supports, so I decided to try it out myself. The OpenAPI…
MiguelMunoz
  • 4,548
  • 3
  • 34
  • 51