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

Not able to validate request body in Spring boot with @Valid

I want to validate my request body with @Valid annotation, but it's not working in Spring Boot I have a Request class within JAR file which I can't modify with two fields. One field is of type Object. My controller class accept this class object as…
asp008
  • 147
  • 1
  • 2
  • 12
9
votes
1 answer

Bean Validation's resourcebundle parameterization possibility in JSF 2?

Using the resourcebundle with BV in JSF 2 would look something like this : public class UserBean { @Size(min=13, message="{creditcard.length}") public String getCreditCard() { return this.creditCard; } } And i have to define the…
Bertie
  • 17,277
  • 45
  • 129
  • 182
9
votes
2 answers

Interpolate validation-specific parameters in bean validation message

I have a custom bean validator which checks if a given field on an entity is unique for some conditions. If the validation fails, the message should include a field (e.g. the ID) of the already existing entity. So for example the message should…
robinst
  • 30,027
  • 10
  • 102
  • 108
9
votes
1 answer

Customizing JAX-RS response when a ConstraintViolationException is thrown by Bean Validation

Bean Validation is a good option to validate objects, but how to customize the response of a REST API (using RESTeasy) when a ConstraintViolationException is thrown? For example: @POST @Path("company") @Consumes("application/json") public void…
Francois
  • 93
  • 1
  • 5
9
votes
3 answers

javax validation size trim whitespace

I need to validate a field in POJO, it must be min length = 2, ignoring leading and trailing whitespaces class User { @NotBlank @Size(min = 2) private String name; } it not works for " A" How it should be?
Romper
  • 2,009
  • 3
  • 24
  • 43
9
votes
3 answers

Spring Boot JSR-303/349 configuration

In my Spring Boot 1.5.1 application I'm trying to configure support of JSR-303 / JSR-349 validation. I have added a following annotations @NotNull @Size(min = 1) to my method: @Service @Transactional public class DecisionDaoImpl extends BaseDao…
alexanoid
  • 24,051
  • 54
  • 210
  • 410
9
votes
3 answers

Spring MVC and JSR-303 hibernate conditional validation

I've a form I want to validate. It contains 2 Address variables. address1 has always to be validated, address2 has to be validated based on some conditions public class MyForm { String name; @Valid Address address1; Address address2; …
mickthompson
  • 5,442
  • 11
  • 47
  • 59
9
votes
1 answer

SmartValidator - manually calling validate with groups

Spring 4.3.2 I need to call SmartValidator.validate() manually and I need it utilize the validation groups that I have defined on the target entity. The javadoc says this... "This variant of validate() supports validation hints, such as …
Jim Ott
  • 725
  • 13
  • 24
9
votes
1 answer

nested Annotation List in Scala

Help, how do i do stuff like the following in Scala? import org.hibernate.validator.constraints.ScriptAssert @ScriptAssert.List({ @ScriptAssert(script = "...", lang = "javascript"), @ScriptAssert(script = "...", lang = "javascript")})
9
votes
3 answers

How to get the payload property from bean validation annotation

I have a class with validation annotations on my properties, like this one: @NotNull(payload = INVALID_CATEGORY_DESCRIPTION.class) @Size(min = 1, max = 255, payload = INVALID_CATEGORY_DESCRIPTION_LENGHT.class) private String description; Then I…
Paulo Pedroso
  • 3,555
  • 2
  • 29
  • 34
9
votes
4 answers

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Integer

I have to take input for paper_name and date_of_birth as int and date datatype respectively from a form. Below is the code:
  • Number:
  • < li>date of birth:
    Md Faisal
    • 2,931
    • 8
    • 29
    • 34
    9
    votes
    3 answers

    JPA Validation of Email String Collection

    I have a list of String in my bean. These strings are email and I would like to validate them. @Email @ElementCollection(fetch = FetchType.LAZY) @OrderColumn private List emails = new ArrayList(); At execution, I got this…
    mcspiral
    • 147
    • 1
    • 10
    9
    votes
    1 answer

    query parameter validation with Jersey

    I'm using Jersey in Java for a simple web server. I'm trying to handle with url query parameters, like /path?value1=X&value2=Y&value3=Z I was able to extract the query value by using the @QueryParam annotation…
    user5317970
    • 91
    • 1
    • 1
    • 2
    9
    votes
    1 answer

    How to validate 2 field with OR condition?

    I want to validate two fields of a Request Class in manner that Either one field is valid OR another field is valid. Eg: Request Bean public class CarRequest { @NotEmpty private String customerName; @NotEmpty private String…
    praveen jain
    • 778
    • 2
    • 8
    • 23
    9
    votes
    6 answers

    JSR-303 dependency injection and Hibernate

    Spring 3.0.2, Hibernate 3.5.0, Hibernate-Validator 4.0.2.GA I am trying to inject Spring dependencies into a ConstraintValidator using: @PersistenceContext private EntityManager entityManager; I have configured the application context with: