OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.13k stars 575 forks source link

BETA BLOG - Preview of Jakarta Validation 3.1 #28397

Open mswatosh opened 3 weeks ago

mswatosh commented 3 weeks ago

The information you provide here will be included in the Open Liberty beta blog post (example), which will be published on openliberty.io/blog/, and potentially elsewhere, to promote this beta feature/function of Open Liberty. For this post to be included in the beta issue please make sure that this is completed by the end of Friday following the GM (Tuesday). The beta and release blogs are created using automation and rely on you following the template's structure. DO NOT REMOVE/ALTER THE <GHA> TAGS THROUGHOUT THIS TEMPLATE.

Please provide the following information: ​

  1. Which Liberty feature(s) does your update relate to?

    Human-readable name (eg WebSockets feature): Jakarta Validation

    Short feature name (eg websockets-1.0): beanvalidation-3.1

  2. Who is the target persona? Who do you expect to use the update? eg application developer, operations.
    Application Developer

  3. Provide a summary of the update, including the following points:

    • A sentence or two that introduces the update to someone new to the general technology/concept.

    • What was the problem before and how does your update make their life better? (Why should they care?)

    • Briefly explain how to make your update work. Include screenshots, diagrams, and/or code snippets, and provide a server.xml snippet.

    • Where can they find out more about this specific update (eg Open Liberty docs, Javadoc) and/or the wider technology?

Jakarta Validation provides a mechanism for validating constraints imposed on Java objects using annotations. The most noticeable change in version 3.1 is the name change, from Jakarta Bean Validation to just Jakarta Validation. There is also explicit support for validating Java Records, which were added in Java 16. Records reduce a lot of the boilerplate code in simple data classes, and pairs nicely with Jakarta Validation.

public record Employee(@NotNull String empid, @Valid EmailAddress email) {}
Employee employee = new Employee("12432", new EmailAddress("mark@example.com"));
Set<ConstraintViolation<Employee>> violations = validator.validate(employee);
</GHA-BLOG-SUMMARY>

What happens next?