spring-validation

Apply Jakarta Bean Validation constraints to Spring Boot DTOs and controllers.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/dprice-dev/claude-java-skills --skill spring-validation-dprice-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-validation
Source: https://github.com/dprice-dev/claude-java-skills/tree/main/.claude/skills/spring-validation
Command: npx skills add https://github.com/dprice-dev/claude-java-skills --skill spring-validation-dprice-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Spring Boot endpoints and service methods often accept untrusted client input, leading to inconsistent null handling, scattered checks, and unclear error responses. This Skill centralizes Jakarta Bean Validation patterns so request DTOs, method parameters, and error handling behave predictably across your API.

Core Features & Use Cases

  • DTO and record constraint validation: Use @Valid, @Validated, and standard constraints (@NotBlank, @Email, @Size, @Past, etc.) to validate incoming payloads and nested objects.
  • Custom constraint annotations and validators: Implement domain-specific rules via @Constraint(validatedBy=...) such as phone number formats or business-date rules.
  • Cross-field and service-layer validation: Apply class-level validators for multi-field rules (e.g., password confirmation matching) and enable method parameter validation using @Validated on services.
  • Group sequences and targeted validation: Use validation groups to run only the appropriate constraints for create vs update flows.
  • Consistent validation error handling: Convert MethodArgumentNotValidException and ConstraintViolationException into structured HTTP responses (e.g., ProblemDetail with field-level errors).

Quick Start

Ask for a Spring Boot controller endpoint and request record that validate input with @Valid, implement one custom annotation, add a cross-field rule, and return a ProblemDetail containing field-level errors.

Frequently Asked Questions about spring-validation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate Spring Boot request DTOs using Jakarta Bean Validation?

Validate Spring Boot request DTOs by annotating record fields with standard Jakarta constraints like @NotBlank and @Email, then triggering validation at controller entry points using @Valid or @Validated. This ensures incoming payloads are checked before processing.

How do I create a custom validator for cross-field validation in Spring Boot?

Create custom validators for cross-field validation in Spring Boot by defining a class-level constraint annotation with @Constraint and implementing a ConstraintValidator to enforce multi-field rules like password confirmation matching across the entire object.

What is the best way to handle ConstraintViolationException in a Spring Boot API?

The best way to handle ConstraintViolationException in a Spring Boot API is to convert it into a structured HTTP response, such as a ProblemDetail object containing standardized field-level errors for consistent and clear client feedback.

Can I use validation groups to separate create and update constraints in Spring Boot?

Yes, you can use validation groups in Spring Boot to separate create and update constraints. By assigning constraints to specific groups and triggering them with @Validated, only the appropriate rules run for each specific workflow.

How do I apply method-level validation to Spring Boot service parameters?

Apply method-level validation to Spring Boot service parameters by annotating the service class with @Validated and adding standard Jakarta constraints directly to method parameters to ensure method entry points validate untrusted arguments.