spring
Validating nested objects and collections.
1. Nested Objects:
Use @Valid on the nested object field inside your DTO.
public class UserDTO { @Valid private AddressDTO address; }
2. Collections:
To validate a list of objects, you can use @Valid as well:
public void saveUsers(@RequestBody @Valid List<UserDTO> users) { ... }
Note: For method-level validation of collections, you often need @Validated on the Class level.