Without @Valid the constraints on your DTO are ignored and invalid data reaches your service.
record OrderRequest(
@NotBlank String sku,
@Min(1) int qty,
@Email String contact) { }
@PostMapping("/orders")
Order create(@Valid @RequestBody OrderRequest body) { ... }
POST with qty = 0 returns:
400 Bad Request
{"errors":[{"field":"qty","message":"must be greater than or equal to 1"}]}
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11