Quick revision
The short answer
@Valid on the controller parameter validates the CustomerDto itself, but validation does not go into a nested object unless that field is also marked with @Valid. The fix is to annotate the address field in CustomerDto with @Valid, to write List<@Valid Address> for collections, and to add @NotNull to the address if it is required, because a null address is never cascaded into and passes.
What to remember
In this answer, we saw that @Valid on the controller parameter validates only CustomerDto's own constraints, and that validation cascades into a nested object only when the field is annotated with @Valid. We fixed the address with @Valid on the field, used List<@Valid AddressDto> for collections, and added @NotNull because a null address is skipped by cascading and passes validation.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@Valid on the controller parameter validates the CustomerDto itself, but validation does not go into a nested object unless that field is also marked with @Valid. The fix is to annotate the address field in CustomerDto with @Valid, to write List<@Valid Address> for collections, and to add @NotNull to the address if it is required, because a null address is never cascaded into and passes.
Why this question is asked
This is one of the most common validation bugs in Spring applications: everything looks annotated, the top-level fields are clearly checked, yet invalid nested data reaches the database. It usually surfaces as a not-null violation from the database or, worse, as bad data nobody notices. Interviewers like it because the fix is one annotation, but the reason teaches how cascading validation works. In this answer, we will reproduce the bug, see why validation stops at the address, fix it for single objects and lists, and deal with a missing address.
1Reproducing the Problem
Here are the DTOs and the controller as they are in the question.
Notice that the name is checked correctly, which proves validation is wired up and the provider is on the classpath. Only the nested constraints are ignored. So the problem is not the setup, it is how far validation goes.
2Why Validation Stops at the Address
When the validator checks an object, it evaluates the constraints declared on that object's own fields. For a field whose type is another class, it sees a reference and checks only constraints placed directly on that field, such as @NotNull. It does not walk into the referenced object, because the specification makes that an explicit choice called cascading. Walking into every reference automatically would be expensive and dangerous: it could validate huge object graphs, lazy JPA collections or cycles.
Cascading is requested with @Valid on the field. The @Valid on the controller parameter is a different use of the same annotation: it says validate this argument, which means CustomerDto's own constraints. It does not mean validate everything reachable from it.
- Validate CustomerDtocheck name:
@NotBlank - Is address marked @Valid?YesValidate AddressDto tooNoStop; street and city never checked
- Is address null?YesSkip it, nothing to cascade intoNoCheck street and city
3 steps in order. Play them, or step through them one at a time.
3The Fix: @Valid on the Field
We add @Valid to the address field. Now the validator goes into the address and reports violations with a path that includes the field name.
The path address.street is useful for clients, because a form can attach the message to the right input. Cascading also goes as deep as the annotations go: if AddressDto had a @Valid GeoPoint location, its constraints would be checked as well, and a validation group used on the controller parameter is applied to every level.
4Lists, Sets and Maps
Customers often have several addresses. For a collection, we want each element validated, and since Bean Validation 2.0 we express that by putting @Valid on the type argument, the part inside the angle brackets.
The older form, @Valid on the list field itself, also cascades into the elements and still works, but the type-argument form says exactly what is validated and is the one to use in new code. For a map, Map<String, @Valid AddressDto> validates the values, and @Size or @NotNull on the field still describe the collection itself.
5Do Not Forget a Null Address
There is one more case. If the client sends no address at all, the field is null. Cascading has nothing to go into, and, as with almost every constraint, null counts as valid. So {"name": "Ana"} still passes after our fix.
So the complete answer has two parts: @Valid to check what is inside the address when it is there, and @NotNull when the address itself is required. A test for each case, an invalid nested field and a missing address, keeps both from regressing.
6Follow-up questions
Why not make cascading the default?
Because object graphs can be large, cyclic or lazily loaded. Automatic cascading into a JPA entity's collections could trigger database queries or a LazyInitializationException during validation. Making cascading explicit keeps validation predictable and cheap.
Does @Validated on the field work instead of @Valid?
No. @Validated cannot be placed on fields at all; its targets are types, methods and parameters. Cascading is a Jakarta Validation feature and is always requested with @Valid, even when the top-level validation uses @Validated with groups.
Does the same rule apply to method validation on services?
Yes. With @Validated on a service class, a parameter like create(CustomerDto dto) has its constraints checked only if the parameter is marked @Valid, and nested objects inside it again need @Valid on their fields.
7Conclusion
In this answer, we saw that @Valid on the controller parameter validates only CustomerDto's own constraints, and that validation cascades into a nested object only when the field is annotated with @Valid. We fixed the address with @Valid on the field, used List<@Valid AddressDto> for collections, and added @NotNull because a null address is skipped by cascading and passes validation.
Open with
The @Valid on the controller parameter only validates CustomerDto's own constraints. The validator checks the fields of that object, and for a field that points to another object it does not go inside unless we ask it to.
Then, if they want more
Going inside is called cascading, and in Jakarta Validation it is always explicit, with @Valid on the field. It is explicit on purpose, because automatic cascading could walk huge or cyclic graphs or lazy JPA collections. We can see that validation itself works, because a blank name is rejected; only the nested street is ignored.
So the fix is to put @Valid on the address field in CustomerDto. Then a blank street fails with the path address.street, which is nice for clients. If the customer has a list of addresses, I would write List<@Valid AddressDto>, which validates every element and reports paths like addresses[1].street.
There is one more gap: if the address is missing, the field is null, there is nothing to cascade into, and null is valid for almost every constraint, so the request still passes. If the address is required, I add @NotNull next to @Valid. I would add two tests, one with an invalid street and one without an address.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A request with an invalid nested address passes validation, although Address has...": https://scrivio-interview-library.netlify.app/spring-boot/request-validation/8362769a16/