Is there a common constraint library for jsr 303 (Bean Validation)?
Asked Answered
C

4

6

JSR 303 Bean Validation contains out of the box some constrains, but also allow to define custom constrains.

I have the feeling that there are a lot of constraints common for a lot of projects that are not shipped with the JSR implementations.

So my question is: Is there a (trustworthy) library that contains commons jsr 303 (Bean Validation) constraints?

Crenulation answered 12/2, 2013 at 10:40 Comment(0)
H
4

I'm not aware of a dedicated constraint library, but the JSR 303 reference implementation Hibernate Validator provides several additional constraints, such as @Email, @ScriptAssert, @URL etc. (disclaimer: I'm contributing to Hibernate Validator).

If you have additional ideas or requirements for other constraints, feel free to create a feature request in our JIRA instance.

Hootman answered 12/2, 2013 at 14:50 Comment(1)
Accept the answer because of "I'm not aware of a dedicated constraint library," - this seams to be the (at the moment) correct answer. -- Let me say that I have huge respect of Hibernate Validator, I use it and I like it. But I do not think that common constraints should be part of an JSR303-Implementation. Because they are implementation independent, so they should be collected in an independent libary or at least an separate jar.Crenulation
R
3

I came to the same result that there is no such library. So I decided to share my little set of common constraints and its validators: https://github.com/malkusch/validation

Rataplan answered 13/12, 2013 at 19:18 Comment(1)
Link has broken.Belgian
F
1

Java Bean Validation Extension (jbvext)

Since 2017 there is the Java Bean Validation Extension (jbvext) library that has among other things the @Before, @After and @Password annotations to fulfill some of OP's wishes.

⚠ Though this library considers null values a fail, the Bean Validation specification recommends null values as being valid.

Filide answered 5/7, 2021 at 7:9 Comment(0)
C
1

Bean Validation 2.0

Bean Validation 2.0 brought several useful additional validations, now built-in.

This includes support for @Past/@PastOrPresent & @Future/@FutureOrPresent with the modern java.time types such as LocalDate that supplanted the legacy Date/Calendar/Timestamp classes.

You will also find constraints like:

  • @NotEmpty/@NotBlank
  • @Email
  • @Positive/@Negative/…

Hibernate Validator

The later versions of the Bean Validation spec have only a single implementation available: Hibernate Validator.

Hibernate Validator implements all the constraints required by the Bean Validation spec. Hibernate Validator implements additional ones as well.

See this list found in Hibernate Validator version 7.0.1. They include constraints for credit cards and currency, durations, bar codes and book IDs (ISBN), text length and Luhn checksum, URLs, collection distinctness, custom constraints written in a scripting language, and more.


For more info about modern Bean Validation, see:

Caudle answered 5/7, 2021 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.