Introduction
Validity is a validation library for Kotlin. You describe the rules of your data in plain Kotlin, next to the data, and Validity reports every rule that is broken, each with a path, a message for people and a code for programs.User.kt
Features
- Plain Kotlin: no annotations, no code generation, no reflection
- Every broken rule at once, with paths into nested objects, lists and maps
- Conditions are ordinary
ifandwhen - Rules across fields, and rules that depend on the caller
- Rules can call
suspendfunctions, such as a database lookup - 175 built-in constraints, with documents of 14 countries and postal codes of 72
- Messages you can translate, and codes that never change
- Depends only on the Kotlin standard library and kotlinx.coroutines
Installation
validity-phone. See Installation for the modules
and the imports.
Validity provides an MCP server that agents can use to search these docs, and an
/llms.txt file at the root of this site.
Requirements
Validity runs on Java 17 or newer and is built with Kotlin 2.4.Next
Quick start
Validate your first class.
Why Validity
The ideas, and how it compares.
Constraints
All 175, by type of value.