@Valid is not working with RequestBody in Sptring 3.0.5. Below is code snippets . Please suggest what is causing the issue.
pom.xml file
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
Conroller:
@RequestMapping(value = "/ValidateCustomer", method = RequestMethod.POST, headers="content-type=application/json")
@ResponseBody
public String validateCustomer(@Valid @RequestBody Customer customer) throws Exception {
// further processing"
return "Validated";
}
Customer class:
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
public class Customer {
@NotNull
private String userId;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
private String companyName;
/* getter and setter methods */
}
Below is the payload requested from postman which should fail to the request, but receiving success message.
{ "firstName":"abc", "lastName": "xyz", "companyName":"abc Corp" }