Skip to content

rulii-bean-validation 1.0.0

rulii-bean-validation 1.0.0 is the first release of a new library, on rulii 2.2.0, the jakarta.validation API 3.1 and Java 17. It reads the jakarta.validation constraints on your beans and turns each one into a rulii rule: named, described, categorised under the bean class and tagged with its groups, visible in the trace and listable from the registry. To the rest of your code it is a Bean Validation provider: BeanValidator implements jakarta.validation.Validator, a validation returns 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, paths and messages.

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 for logic the specification does not give you. This library keeps everything the annotations do and adds three things:

  • @Validate attaches a rule, rule set or rule flow from a rulii RuleRegistry to a class, property, method or constructor, by name. What runs under that name can change at runtime without touching the bean.
  • @Expr is an inline cross-field condition in any scripting language rulii knows: @Expr(value = "#{end.isAfter(start)}", errorCode = "trip.end"). The language comes from the annotation, from @ExprDefaults on the class or package, or from rulii.script.defaultLanguage; it is never guessed.
  • @Bind parameterises one registered rule per declaration site, the way max = 10 parameterises @Size.

The line the library draws: annotations describe what is intrinsic to the data; rules decide what is contextual. The test for an @Expr is whether the condition would ever change for a business reason. If yes, it is a rule.

All 22 built-in Jakarta constraints, groups and sequences, @ConvertGroup, cascading, container element constraints with value extractors, method and constructor validation, the metadata API and the default message interpolation. The constraints Hibernate Validator users know are there too, under org.rulii.validation.beans.constraints with the same names and attributes: @UUID, @ISBN, @EAN, @CreditCardNumber, @LuhnCheck, @Mod10Check, @Mod11Check, @UniqueElements, @Normalized, @CodePointLength, @Length, @Range, @URL, @DurationMin and @DurationMax, each backed by a rulii validator added in 2.2.0.

The library is not a certified implementation and does not run the TCK. The specification coverage page lists every known deviation, chapter by chapter, and the migration guide says what a project coming from Hibernate Validator will notice.

rulii-spring 2.2.0 brings this library in and makes it the application’s Validator, wired into the Spring rulii context: @Validate names are bean names, constraint validators are Spring beans, and the provider is selected even with Hibernate Validator still on the classpath. The explorer 1.1.0 shows the validated beans and the rules behind every constraint.

Start with Validating Beans.