A lightweight approach for a simple validation library for Java to validate complex objects with a fluent API.
✅ Fluent API – Reads like natural language
✅ Type-safe – Leverages Java's type system with generics
✅ Fail-slow – Collects all errors, not just the first one
✅ Dynamic – Build validations at runtime; no annotations required
✅ Extensible – Add custom validation logic with lambdas
✅ Zero runtime dependencies – Lightweight library for production use
Add the following dependency to your pom.xml:
<dependency>
<groupId>de.hofmann-hbm.zoda</groupId>
<artifactId>zoda-validation</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>import de.hofmannhbm.zoda.Validator;
import de.hofmannhbm.zoda.ValidationResult;
ValidationResult result = Validator.of(user)
.check(User::getName, "Name")
.isNotNull()
.matches(n -> n.length() > 3, "must be longer than 3 characters")
.and()
.check(User::getAge, "Age")
.matches(age -> age >= 18, "must be at least 18")
.and()
.validate();
if (!result.isValid()) {
result.getErrors().forEach(e ->
System.out.println(e.fieldName() + ": " + e.message())
);
}