A lightweight Java library for validating JSON against Java DTOs using Jackson 3 and Jakarta Bean Validation.
It avoids JSON Schema complexity by treating your Java classes (DTOs) as the schema definition.
Detailed documentation is available in the docs folder:
- Getting Started: Installation and basic "Hello World" example.
- Advanced Usage: Nested validation, collections, and custom constraints.
- Configuration: Customizing the Jackson Mapper and Validator.
- Error Handling: Understanding and using
ValidationResult.
<dependency>
<groupId>io.github.dogrulabs</groupId>
<artifactId>jackson3-json-validation</artifactId>
<version>1.0.0</version>
</dependency>// 1. Define DTO
public class UserDto {
@NotNull
public String username;
}
// 2. Validate
JsonValidator validator = JsonValidators.defaultValidator();
ValidationResult result = validator.validate("{\"username\": null}", UserDto.class);
if (!result.valid()) {
System.out.println(result.errors()); // [ValidationError(path=username, message=must not be null)]
}- Java 17 baseline.
- Jackson 3 (
tools.jackson.*) for JSON parsing and binding. - Jakarta Bean Validation 3.0+ for constraints.
- Zero Boilerplate: No manual schema definition required.
- Simple API: Functional API returning a clear
ValidationResult.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.