Announcement Announcement Module
No announcement yet.
Spring MVC 3.2 - JSR 303 Validation is not working. JSON POST Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC 3.2 - JSR 303 Validation is not working. JSON POST

    I have the following Bean...
    public class Person {
    private Integer person_id;
    private String name;
    private String name2;
    private String email;
    private double phone;
    private String desc;
    @Column (name="id")
    public Integer getPerson_id() {
        return person_id;
    public void setPerson_id(Integer person_id) {
        this.person_id = person_id;
    @Column (name="fn")
    public String getName() {
        return name;
    public void setName(String name) { = name;
    public String getName2() {
        return name2;
    public void setName2(String name2) {
        this.name2 = name2;
    @Column (name="em", unique = true)
    public String getEmail() {
        return email;
    public void setEmail(String email) { = email;
    public double getPhone() {
        return phone;
    public void setPhone(double phone) { = phone;
    @Column (name="de")
    public String getDesc() {
        return desc;
    public void setDesc(String desc) {
        this.desc = desc;
    My POST Controller method:

    @RequestMapping(value="/persons", method = RequestMethod.POST, 
                                     headers = "Accept=*/*", 
                                    consumes = "application/json")
    public String getAllPersons( @javax.validation.Valid @RequestBody Person p){
        System.out.println("The OBject:" + p);
        personService.savePerson(p); // The validation is kicking in this method.
        return "redirect:persons.htm";
    My Config file:

    		<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
    		<context:component-scan base-package="com.springmvcsample"/>
    		<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        		<!-- Turn off working out content type based on URL file extension, should fall back to looking at the Accept headers -->
        		<property name="favorPathExtension" value="false" />
    I have Hibernate Validator jar in my classpath along with Spring validation API jar.

    The binding is working fine. But validation is not applying. Note that I am posting JSON. Not form.
    However, when I save the bean (Hibernate), the validation kicks in.

    What am I missing here?

  • #2
    Anyone? Any idea?