Spring MVC 3 nested object validation is failing with @Valid
bean-validation, spring, spring-mvc
Solution
As far as I know, `@NotNull` isn't quite right for String validation, since the Spring-model often mapping "no object received" to "blank string" instead.
Please try `@NotBlank` and sees if the BindingResults return errors.
Problem
I have following nested objects. I am using @Valid for validation in my controller. Here BindingResult object is not validating name field of Child object. Am I missing anything? ``` class Parent{ @Valid private Child child; //getter and setter for child object } class Child{ @NotNull(messag="Name cannot be null") private String name; //getter and setter for name } My controller validate method @RequestMapping(value = "/validate", method = RequestMethod.POST) public @ResponseBody String validate(@Valid @ModelAttribute("parent") Parent parent, BindingResult bindingResult) { //Here I can see child name value if I say parent.getChild().getName() // But if parent.getChild().getName() is null, bindingResult.hasErrors() is returning false } ```