AnViL - Annotation Validation Library¶
Anvil is a powerful and type-safe Java validation library for JSON deserialization with annotation-based schema validation. It provides declarative validation rules that ensure your data meets the requirements before it is processed.
Features¶
✨ Declarative Validation - Define validation rules using simple annotations.
🎯 Type-Safe - Full compile-time type checking with Java generics.
🔌 Multiple JSON Processors - Built-in support for Gson and Jackson.
📝 Rich Annotation Set - Comprehensive validation annotations for all common scenarios.
⚡️ Fail-Fast Mode - Stop validation on first error.
🎨 Extensible - Easy to add custom validators and processors.
🔍 Detailed Error Messages - Clear validation errors with field-level granularity.
Why Anvil?¶
- Declarative Validation: Define rules with annotations instead of imperative code.
- Framework Agnostic: Works with Gson, Jackson, or implement your own processor.
- Rich Annotations: Numeric comparisons, string matching, enums, and custom validators.
- Developer Friendly: Clear error messages and fail-fast validation.
Modules¶
Anvil is split into three modules:
- anvil-core - Core annotations and validation framework.
- anvil-processor-gson - Gson processor implementation.
- anvil-processor-jackson - Jackson processor implementation.
Choose the processor that matches your JSON library!
Installation¶
anvil-core¶
anvil-processor-gson¶
anvil-processor-jackson¶
Requirements¶
- Java 21 or higher
Quick Start¶
@Validate
public class User implements Schema {
private String username;
@Between(min = 18, max = 120)
private Integer age;
@In({"admin", "user", "guest"})
private String role;
}
Note
This is a simplified example. See the Getting Started guide for full details, including processor configuration and validation workflow.
Documentation¶
The full Javadocs are available here.
Tip
If you want to see the Javadoc for any of the processor modules, just change anvil-core in the top bar to the
desired module name, e.g., anvil-processor-gson or anvil-processor-jackson.