Card 02/ 06

ExampleDifficulty: Intermediate1 min

@Valid Is What Makes It Run

The constraint annotations from the previous card do nothing by themselves. @Valid on the controller parameter is what tells Spring to actually check them before the method body runs.

java
@PostMapping("/rides")
ResponseEntity<String> createRide(@Valid @RequestBody RideRequest request) {
    return ResponseEntity.ok("created: " + request);
}
text
POST /rides, body {"pickup":"","passengers":0}
-> 400 Bad Request
run in a container — the method body never executes

An empty pickup and a passengers of 0 both violate a constraint from the previous card, and the request never reaches createRide's body at all — Spring rejects it before your own code runs.