First milestone release of Jakarta Validation 4.0
Recently, we published the first milestone release of the upcoming Jakarta Validation 4.0. Jakarta Validation 4.0 will be a part of the Jakarta EE 12 platform, to be released later.
What has been done so far?
The 4.0 update of the specification, compared to 3.1, brings the following changes:
-
Easier Custom Constraint Validator Integration: developers of custom constraints can now declare their
ConstraintValidatorimplementations using the Java Service Loader mechanism. This decouples the constraint definition and the constraint validator implementation details. It especially simplifies the process for external libraries to add support for more types to constraints existing in other libraries, including the default, Jakarta Validation ones. -
Optional
validatedByAttribute: ThevalidatedByattribute on thejakarta.validation.Constraintannotation is now optional. It defaults to an empty array, which cleans up the code when you don’t need to specify validators explicitly, for example, when you define your constraint validators through a service loader mechanism. -
Simplified Attribute Retrieval: We’ve introduced a simpler, more direct way to fetch a single attribute from a
ConstraintDescriptor. This reduces the boilerplate type casts. -
Clarified Number Validation for Strings: Both
@Minand@Maxconstraints were already able to validate the string representation of numbers, as the TCK was testing for it. Hence, from now on, it is explicitly mentioned that these constraints are applicable to Strings. This also better matches the behaviour of their decimal counterparts:@DecimalMinand@DecimalMax -
Formal Deprecation of
ConstraintViolationBuilderMethods: Some methods in theConstraintViolationBuilderthat were previously marked as deprecated only in the Javadoc comments are now formally deprecated. This makes it clearer which methods you should avoid using going forward and sets the stage for future removals.
What won’t be getting in?
We were exploring the possibility of relaxing some of the XML schema validation constraints. But with what is currently available in the XSD specification, there is not much we can change, hence this idea is put on hold.
What is yet to come?
There are still a few things to address and some ongoing discussions about potential improvements. In particular:
-
We are planning to make it clear that after Jakarta Validation 4.0 the legacy approach to cascading validation will be removed.
@Valid // (1) List<MyObject> legacyObjects; List<@Valid MyObject> objects; // (2)
-
The legacy approach to applying cascading validation to list elements.
-
The modern approach to applying cascading validation to list elements. Available since Bean Validation 2.0.
Moving forward (e.g. in Jakarta Validation 5), keeping the "legacy" approach in place would result in an attempt to validate the container itself (i.e. the list in this case) instead of validating the container elements.
We encourage users to finally move away from the legacy approach.
-
-
There is also a discussion on providing access to the initialization context within the constraint validator initialization step. Currently,
ConstraintValidator#initialize(..)method only exposes the constraint annotation to theConstraintValidatorimplementer. However, it may be useful for some constraints to obtain more information at this stage. For example, constraints dealing with temporal types may need to get their hand on theClockProvider, or get access to some of the Jakarta Validation provider-specific details.
Upcoming Jakarta Validation 4.0
Jakarta Validation 4.0 is on its way, as the release plan for this version was approved exactly one month ago on May 6!
What to expect from Jakarta Validation 4.0?
The highlights of this release plan are as follows:
-
This version of the specification will require Java SE 21 or higher.
-
Prepare for removal of the legacy approach to mark container elements for cascading validation, i.e.
@Valid List<MyBean> list;. The next major version will consider such code to be requesting the cascading validation of theList, and not its elements. It’s time to finally switch any remaining code using this approach to the much more encouraged and cleanerList<@Valid MyBean> list;If you have a particular use case where you think that you won’t be able to express your constraints without relying on the legacy approach — please reach out on the corresponding issue. -
Introduce an alternative initialization method
ConstraintValidator#initializeto provide more context than just the annotation so that it would be possible to use a more eager approach to initializing the constraint validator. -
Relax element order in the XSD where it doesn’t matter.
-
Add support for
ConstraintValidatordeclaration via service loader. -
Remove any uses of the
SecurityManageras it’s being deprecated without an alternative for some time now. -
Reevaluate the value extraction for
Optionaland whethernullshould be passed as an extracted value for empty optionals. -
Other more minor clarifications, cleanups and improvements.
Join the discussions at the issue tracker, or bring your proposals for future consideration.
Jakarta Validation 3.1 specification
Jakarta Validation 3.1 was released earlier in 2024.
What’s new in Bean Validation 3.1?
The 3.1 update of the specification, compared to 3.0, brings the following changes:
-
The minimum required Java version is set to 17.
-
The rename of the specification from Jakarta Bean Validation to Jakarta Validation.
-
The clarification on the record validation.
Jakarta Validation 3.1 will be a part of the Jakarta EE 11 platform, to be released later.
Give it a try
Don’t wait and try out the new release yourself! Just get the Hibernate Validator implementation, read the Getting started section of its reference guide. You also can read the complete specification as well as the API docs.
Bean Validation 2.0 - What’s in it?
While a couple of months have passed since Bean Validation 2.0 got released, the info about what’s new in the spec may still not yet have reached everyone. Here are two presentations which I wanted to share in order to help with that.
The first one is the slide set of the talk on Bean Validation 2.0 and JSR 380 which I did at JavaOne 2017:
You can also download a PDF with these slides from Speaker Deck here.
While the JavaOne session was not recorded, my quickie session on the same topic at Devoxx 2017 luckily was. In just 14:17 min you’ll get an overview on the new spec revision. It’s lots of contents for the short amount of time, but you can pause and rewind as often as you like ;)
Feedback
You got feedback on these presentations or just have a general question around Bean Validation? Then let us know by adding a comment below or sending a message to the Bean Validation mailing list.
While at the moment no work on the spec itself is going on, we’re eager to explore new features in the reference implementation. So if there’s something which you think should be added in a future spec revision, it’s the perfect time to get in touch so we can begin to experiment with these things.
Your feature requests (and pull requests) will be highly welcomed!
Bean Validation has a new website!
Bean Validation just got a new website and we hope you will like it!
New layout
We developed a more modern layout based on Semantic UI.
It should be easier to the eye and more readable too.
The logo, contributed by Hendrik Ebbers for Bean Validation 2.0, is now in good place.
New organization
In the old website, the information about a given version of the spec was spread over multiple pages. It was hard for the user to get an overview of a given version and it was also hard for us to work on new versions of the spec.
We changed the website organization to centralize all the information of a spec release on one page.
See for instance:
The main changes, the TCK and the certified implementations are all accessible from these landing pages.
A bright future
The last version of the spec has a prominent link in the menu and you can find the old versions of the spec in the archives.
Presenting a new version of the spec should be easier than ever. That was our ultimate goal.
Feedback
As usual, if you have some feedback or if you find an issue in the new website, either add a comment just below or post something on the Bean Validation mailing list.
Latest news
Stay up to date, subscribe to the news feed.