Posts

Showing posts from October, 2022

Java Bean IBAN Validation - Creating custom constraint annotation

Image
  Although Bean Validation has plenty of handy built-in constraints, such as to make sure if a field is following a specific regex or even if a date is in the past or future, it is certain that soon or later you will need a specific constraint that is not covered by the standard annotations.  Definition of ConstraintValidator Definition of Constraint Custom constraints are at the heart of JSR 303 Bean Validation flexibility.

Triggering Bean Validation programmatically

Image
Validation in Spring Boot applications can be done in many different ways. Why validation? Validating incoming request data is good to reject nonsense as early as possible. Persistence layer validation should only be used as additional layer of safety. I prefere validation programmatically even if triggering Bean Validation programmatically takes a bit more effort. I think it is usually the most flexible way. Validation is done by using the Bean Validation API. The reference implementation for the Bean Validation API is Hibernate Validator. Triggering Bean Validation programmatically Validating extends SelfValidating class