rulii-bean-validation 1.1.0
rulii-bean-validation 1.1.0 is on Maven Central. It requires rulii 2.3.0; 1.0.0 runs on rulii 2.2.0. The annotations, the API and the violations are unchanged. This release is about what a validation call costs. The full list is in the changelog.
Predefined constraints are checked directly
Section titled “Predefined constraints are checked directly”In 1.0.0 every constraint ran through the rule engine: parameters were matched, a value function was resolved, the rule was run. For @NotNull on a field that is a lot of machinery around one comparison.
In 1.1.0 a rule backed by one of rulii’s own validators (@NotNull, @Size, @Min, @Email and the rest of the standard and library constraints) is asked directly: the value is read, the validator decides, and a failure is reported with the violation the rule builds. Everything that is a rulii feature still runs in the engine, in declaration order with the rest: @Expr, @Validate, a @ReportAsSingleViolation composition and a custom ConstraintValidator. The violations arrive in the same order, and a fail-fast call stops at the same rule.
A plain class needs no engine around it
Section titled “A plain class needs no engine around it”A class with nothing but predefined constraints on its properties is validated without bindings and without a rule flow: validate reads each property once and asks the validators. A cascade does the same when it reaches an object of such a class. A class that declares nothing to validate returns its empty report at once, and a cascade does not descend into it.
Groups, group sequences, fail-fast and the traversable resolver apply as before.
What it adds up to
Section titled “What it adds up to”Validations per second on one thread, measured with JMH on one machine, each release from Maven Central:
| What is validated | 1.0.0 on rulii 2.2.0 | 1.1.0 on rulii 2.3.0 |
|---|---|---|
| A bean of ten satisfied constraints | 34,000 | 640,000 |
| The same bean with three violations | 27,000 | 160,000 |
| An order cascading into ten lines | 4,400 | 120,000 |
| An order cascading into a hundred lines | 590 | 23,000 |
A bean with one custom ConstraintValidator |
220,000 | 800,000 |
Part of the gain is rulii 2.3.0 itself, which made the engine faster; the rest is this release. Two rows show where the engine still does the work: a class with a custom validator keeps its flow, and every violation is built, rendered and stamped with its path when it is reported. Optimizing rulii has the engine’s side of it.
What a listener sees
Section titled “What a listener sees”- A
RuleListenerstill sees every rule, with the same events. - A
RuleSetListenerno longer hears from a validation call: the rules of a bean are not run as a rule set any more. - A
RuleFlowListenerhears of the flows that actually run, so not of a plain object or one with nothing to validate. validateIn, and a bean flow run on its own, are not affected: there every object’s flow runs and is traced.
Behaviour changes
Section titled “Behaviour changes”- A bean flow run on its own keeps its defaults to itself. A flow from
getRuleFlow,getParametersRuleFloworgetReturnValueRuleFlow, run by your code without aruleViolationscollector bound, used to leave its defaulted collector in your bindings. rulii 2.3.0 binds a flow’s defaults in the flow’s own scope, so bind aRuleViolations(aBeanRuleViolationsfor property paths and root beans) asruleViolationsbefore running the flow, and read the report from it.validate,validateInand the Spring integration bind their own collector and are not affected. @Decimalno longer accepts leading or trailing spaces unlessallowSpace = true. The attribute was always documented as false by default; rulii’sdecimalvalidator started with the setting on up to 2.2.0.- Two collectors in one context. When a
RuleViolationsis bound asruleViolationsand another under a different name,validateInand an embedded bean flow report to the one bound asruleViolations.
Jakarta EL as ${...} under Spring
Section titled “Jakarta EL as ${...} under Spring”An @Expr or @Bind(expr = ...) in Jakarta EL written as ${...} now works with rulii-spring, as #{...} always did. With rulii 2.2.0 the expression was taken for a Spring property placeholder and failed. See Jakarta EL in @Expr and @Bind.
Spring Boot
Section titled “Spring Boot”With rulii-spring 2.3.0 this library is opt-in: add it beside rulii-spring and it becomes the application’s Validator. rulii-spring 2.2.0 brought it in itself. See Spring Boot Integration.