The Products API validates all incoming create and update request bodies using Jakarta Bean Validation annotations declared directly onDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ricpalomino/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
ProductRequestDTO. When a request body fails validation, Spring automatically throws MethodArgumentNotValidException before your controller logic runs. GlobalExceptionHandler catches that exception and converts it into a structured 400 response with a field-level error map—no try-catch required in your controller.
ProductRequestDTO
Validation constraints
| Field | Annotation | Rule | Error message |
|---|---|---|---|
name | @NotBlank | Must not be null, empty, or whitespace-only | Nombre del proudcto es requerido |
name | @Size(min=3, max=100) | Length must be between 3 and 100 characters | El nombre del producto debe tener entre 3 y 100 caracteres |
price | @Min(1) | Must be 1 or greater (effectively > 0 for a Double) | El precio del producto debe ser mayor a 0 |
name and price are invalid, the 400 response includes an entry for each failing field.
What happens on a validation failure
When the request body violates one or more constraints, the API returns HTTP 400 with the following JSON shape:data object is a Map<String, String> where each key is the failing field name and each value is the constraint’s message attribute. Multiple failures appear as multiple keys in the same map.
Example: sending a bad request
The following request omitsprice and passes a name that is too short:
Activating validation in the controller
Bean Validation only runs automatically when the controller method parameter is annotated with
@Valid. Without it, the annotations on ProductRequestDTO are ignored and no validation occurs. Confirm that your controller methods that accept a ProductRequestDTO include @Valid: