Jakarta Validation
About
Why is Jakarta Bean Validation important in Spring ?
Jakarta Bean Validation Components
1. Constraint Annotations
2. Meta Annotations
3. Interfaces
4. Bootstrap API
How Spring Integrates with Jakarta Validation ?
Spring Validation Flow
1. Controller-level Validation on @RequestBody DTO
@RequestBody DTO2. Controller-level Validation on @RequestParam, @PathVariable
@RequestParam, @PathVariableInternal Workflow:
3. Nested (Recursive) Validation with @Valid
@ValidInternal Workflow:
4. Service-layer (Method-level) Validation using @Validated
@ValidatedExecution Flow:
Example
Calling code:
Result:
5. Validation Groups Internally
How It Works:
6. Manual Validation using Validator
When and How Validation is Triggered ?
Example
1. DTO With Constraints
2. Populating DTO Manually
What Happens Here?
How to Trigger Validation ?
Option A: Manual Trigger
Option B: Automatically via Spring
Validation Groups
Define Marker Interfaces
Apply to Fields
Validate with Groups
Custom Constraints
1. Define annotation
2. Implement logic
3. Use it in our bean
Last updated