Skip to content

Instantly share code, notes, and snippets.

View Guilherme-Marcionilo's full-sized avatar

Guilherme-Marcionilo

View GitHub Profile
@rponte
rponte / bean-validation-constraint-composition.md
Last active November 30, 2022 01:01
Bean Validation: playing a little bit with Constraint Composition

Bean Validation: Composing Constraints

We can use the Composite Constraint feature to compose many Bean Validation's annotations into a single one custom annotation/validation, as the following code:

import org.hibernate.validator.constraints.CompositionType;
import org.hibernate.validator.constraints.ConstraintComposition;
import org.hibernate.validator.constraints.br.CNPJ;
import org.hibernate.validator.constraints.br.CPF;