Introduction
rulii-bean-validation reads the jakarta.validation constraints on your beans (@NotNull, @Size, @Valid, your own @Constraint annotations) and turns them into rulii rules. Validation then runs on the rulii engine: every constraint is an ordinary rule with a name, a description, a category and tags, every violation is a rulii RuleViolation, and the whole run is visible in the rulii trace.
To the rest of your code it is a Bean Validation provider. BeanValidator implements jakarta.validation.Validator, the result of a validation is a Set<ConstraintViolation<T>>, and the standard bootstrap finds the provider through META-INF/services. A bean annotated for Hibernate Validator validates unchanged, with the same null semantics, the same property paths and the same messages.
Why rulii Bean Validation?
Section titled “Why rulii Bean Validation?”Bean Validation stops at the annotation. A constraint checks one value; anything that looks at two fields, at the state of the system, or at who is asking means a ConstraintValidator class, a class-level annotation and a place to put the logic that the specification does not give you. This library keeps everything the annotations do and adds what they cannot:
| Bean Validation alone | With rulii Bean Validation | |
|---|---|---|
| Standard constraints, groups, cascading, containers, method validation | ✓ | ✓ unchanged |
Cross-field invariant (end after start) |
Class-level annotation plus a validator class | One line: @Expr(value = "#{end.isAfter(start)}", errorCode = "trip.end") |
| Validation that depends on context (the customer, the operation, a limit that changes) | Not its job | A rulii Rule, RuleSet or RuleFlow, attached with @Validate, swappable at runtime |
| Orchestration (run these checks only if those passed, branch, loop over items, run in parallel) | None | RuleFlow |
| Scripted conditions | EL inside messages only | Any JSR-223 language, GraalJS, Groovy, Jakarta EL, in @Expr and in registry rules |
| Seeing what runs | The metadata API | Every constraint is a named, described, tagged rule: list it, trace it, filter it |
| Entry point | Validator |
The same Validator, plus the builder and validateIn for an existing rulii context |
Key Features
Section titled “Key Features”- Keep the annotations, gain the engine The constraints you already have become rules you can list, trace, filter by tag, embed in a
RuleSetorRuleFlow, and run inside a rulii context next to your business rules. - Business rules stay out of the DTO
@Validate("orderRules")names rules in a ruliiRuleRegistry; what runs under that name can change without touching, or recompiling, the bean. - Inline invariants with @Expr A cross-field condition in one line, in Jakarta EL, JavaScript, Groovy or Java:
@Expr(value = "#{end.isAfter(start)}", errorCode = "trip.end"). - One engine for validation and decisions The rules that validate an order and the rules that price it run on the same engine, share bindings, and appear in one trace.
- Drop-in for the reference implementation
Validator,ExecutableValidator,ConstraintValidatorexecution, groups and sequences, group conversion, container element constraints, method and constructor validation, the metadata API and the default message interpolation are all in place. - Two dependencies rulii core and the
jakarta.validationAPI. Nothing else is pulled in.
Annotations for Invariants, Rules for Decisions
Section titled “Annotations for Invariants, Rules for Decisions”The library draws one line, and the rest of the design follows from it:
- Annotations describe what is intrinsic to the data. A code is between 2 and 5 characters, a quantity is positive, a trip ends after it starts. These hold in every conceivable use of the object, so they belong on the class, as constraints or as an
@Expr. - Rules decide what is contextual. Whether a customer may place this order, whether a discount applies, what counts as complete during a draft: these change for business reasons. They belong in the registry, attached with
@Validateor run as your ownRuleFlow, where they are listed and swapped without touching the bean.
The test for an @Expr is simple: would this condition ever change for a business reason? If yes, it is a rule.
A Quick Look
Section titled “A Quick Look”public class Order {
@NotNull @Size(min = 2, max = 5) String code;
@NotNull(groups = OnCreate.class) String reference;
@Valid Customer customer;
@Positive int quantity = 1;}Validator validator = Validation.buildDefaultValidatorFactory().getValidator();Set<ConstraintViolation<Order>> violations = validator.validate(order);That is the whole of it for a bean that only needs the standard constraints. The rest of this guide covers what the annotations cannot do on their own: attaching rulii rules with @Validate, inline conditions with @Expr, cross-field validation with rules, rule sets and flows, and what the library builds behind every constraint.
What Is Different by Design
Section titled “What Is Different by Design”- This is not a certified implementation of the specification and does not aim to pass its TCK. The specification coverage page lists every known difference, chapter by chapter.
- XML configuration (
META-INF/validation.xml, constraint mapping files) is never read. - Method validation is a call you make through
forExecutables(); interception (@ValidateOnExecution, proxies) stays with your framework, as it does with every provider. - The legacy
javax.validationnamespace is not supported. - Hibernate-specific extensions have no equivalent unless listed in the migration guide, which says what to use instead.