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

How to obtain ConstraintValidatorContext?

I am writing code that has explicit call to Bean Validation (JSR-303) something like this: public class Example { @DecimalMin(value = "0") private static final String ANNOTATED = ""; public void isPossitiveNumber(String str){ …
alexsmail
  • 5,661
  • 7
  • 37
  • 57
7
votes
2 answers

JSR-303 validated property does not have a corresponding accessor for Spring data binding

0.4 and hibernate validator 4.1.0.Final, I created a custom validator for validating password and confirmPassword fields, but the validator thrown the following exception: 00:16:11,891 DEBUG…
samsam
  • 71
  • 1
  • 1
  • 4
7
votes
1 answer

Using javax.validation with Tomcat7

I'm trying to get javax.validation working on Tomcat 7. Ive got in my WEB_INF/lib: hibernate-validator-4.3.0 as well as slf4j-api-1.7.1 and slf4j-simple-1.7.1. When I run my code, the validation is just ignored! Its all working fine on glassfish,…
nfvindaloo
  • 948
  • 2
  • 11
  • 24
7
votes
1 answer

Why must JSR303 custom annotation's constrain group default to empty array?

I'm writing a custom validator for a specific constrain group (not Default), but the runtime gives me the below error. I'm just curious why they need the default values to be empty. Appreciate if you can share your opinion. Thanks…
The Huy
  • 71
  • 1
  • 4
6
votes
2 answers

If I use two custom annotations in jsr 303 how to stop validation for second annotation if validation failed on first?

I have the next issue while working with jsr303: i have field annotated the next way: @NotEmpty(message = "Please specify your post code") @PostCode(message = "Your post code is incorrect") private String postCode; But I need to check @PostCode…
6
votes
1 answer

Validation annotation and property file

i have a field in my spring bean (managed bean with jsf) and i am validating on it's length with the @Size annotation using JSR303 bean validation as follows: @Size(min = 7, max = 15, message = "{password.range}") private String newPassword; and i…
fresh_dev
  • 6,694
  • 23
  • 67
  • 95
6
votes
2 answers

springmvc jsr303 validator co-exist with spring WebDataBinder validator in one action

Since springmvc 3.x now supports jsr303 and old spring style validator, i want to mix them in my sample apps. But there is only one method enabled for a specified controller, is that the limit of spring framework or JSR standard? Here is my sample…
Bigfei
  • 116
  • 1
  • 7
6
votes
4 answers

Validation framework in C#?

In the java world there is the bean validation framework JSR-303 which is a nicely well thought out strategy for performing data validation in both the presentation and persistence layers of an application. It covers a lot of things, including…
someName
  • 1,275
  • 2
  • 14
  • 33
6
votes
1 answer

Merging ConstraintViolation set from validator.validate with ConstraintValidatorContext

Is there some method (other than foreach, but good foreach could be sufficient), to return messages from validator.valid from custom ConstraintValidator ? Simple example (yes, I'm trying to do conditional validation) @TestFormConstraint public class…
Adam Jurczyk
  • 2,153
  • 12
  • 16
6
votes
2 answers

JSR303 validation on collection of common objects

Is it possible to validate each element of a collection, based one or more delegate validation rules? For example: @EachElement({@Min(1), @Max(12)}) private Set monthNumbers;
Jeroen
  • 527
  • 2
  • 7
  • 19
6
votes
1 answer

JSR 303 Validation Override

How can I go about overriding the validation on the email for the AuthorizedUser in the following situation: public class Account { @Length(min = 1, max = 100, message = "'Email' must be between 1 and 100 characters in length.") …
Scott
  • 9,458
  • 7
  • 54
  • 81
6
votes
2 answers

SpringBoot with Jakarta Validation Api not validating with @Valid Annotation

i have a question to Spring boot and the dependency jakarta-validation-api. Actually i have a simple DTO which holds some properties. But this properties are not being validated when I call the REST-function within the @Valid annotation. Can someone…
krypto88
  • 161
  • 2
  • 2
  • 5
6
votes
2 answers

What is the use case of javax.validation.Payload in Bean Validation API?

Bean Validation specification defines: Constraint annotations must define a payload element that specifies the payload with which the constraint declaration is associated. The type of the payload parameter is Payload[]. Class[]…
hamidreza75
  • 567
  • 6
  • 15
6
votes
2 answers

How to return the ConstraintViolationException messages in the response body?

I am developing a Spring Boot based REST API. I am validating the input entities using custom ConstraintValidator annotations. My problem is that I cannot return the ConstraintViolationException messages in the response. My exception handler does…
Adrian Pop
  • 215
  • 1
  • 3
  • 12
6
votes
1 answer

How to Throw a Custom Exception When Bean Validation In Spring Boot with Hibernate Validator Fails?

I'm using Spring Boot 2.0.1 with inclusion of validation-starter (which comes with Hibernate Validation 6.x) and trying to validate a method parameter and return objects in my Spring repository layer. There are basically a ParamObj and ReturnObj for…
NuCradle
  • 665
  • 1
  • 9
  • 31