16

Enforcing Java Record Invariants With Bean Validation - Gunnar Morling

 4 years ago
source link: https://www.morling.dev/blog/enforcing-java-record-invariants-with-bean-validation/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Record types are one of the most awaited features in Java 14; they promise to "provide a compact syntax for declaring classes which are transparent holders for shallowly immutable data". One example where records should be beneficial are data transfer objects (DTOs), as e.g. found in the remoting layer of enterprise applications. Typically, certain rules should be applied to the attributes of such DTO, e.g. in terms of allowed values. The goal of this blog post is to explore how such invariants can be enforced on record types, using annotation-based constraints as provided by the Bean Validation API.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK