Graph Validation for Kotlin

Declarative validation of whole object graphs, with every failure reported at its path.

What's inside

Discover the capabilities built to elevate your Kotlin applications.

Validation DSL

Declare rules for properties, collection elements, map keys and values, and no-argument functions alongside each type's graph, selecting members by reference or applying rules to all of them at once.

Built-in Rules

Rules for strings, collections, maps, comparable values, booleans and any value: blank and empty checks, lengths, contents, prefixes and suffixes, regular expressions, UUIDs and Luhn checksums, counts, distinctness, exact contents, keys and entries, ranges, equality, identity and null checks.

Custom and Conditional Rules

Reuse any core Specification as a rule, or write one as a lambda, and override any rule's message. Rules can apply conditionally with whenever and otherwise, and the condition is recorded on any failure it produces.

Nested Validation

Validation descends into nested objects, collection elements and map values that have registered graphs, applying every graph in the class hierarchy and detecting cycles. Require a nested graph to be present, or skip one where descending isn't wanted.

Hierarchical Results

Results mirror the shape of the subject, with the failures at each path, and can be queried by path or wildcard pattern, checked for validity or turned into an exception.

Machine-Readable Failures

Every failure carries its path, a namespaced rule identifier such as string.notBlank, the rule's parameters and a message, so clients can act on failures rather than parse them. Results render as tree- shaped or flat JSON with no extra dependencies.

Stop on the First Error

Collect every failure, or stop at the first when that's all you need to know.

Rules Without a Subject

describe<T>() lists every rule that applies to a type, including conditional branches and subtypes, at wildcard paths, so rules can be documented or shown to users before anything is validated.