0

I am trying to apply validation on REST request using "hibernate-validator-5.1.3.final" jar.I am able to do it for outer bean but not for inner bean.So can anyone help me to do it.Thanks in advance.

Request through Postman

{
    "employeeDetails": [{
                           "employeeId": "123456",
                           "dept" : 101,
                           "salary" : 30000,
                           "status":"active"                              
                }]
}

pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.1.3.Final</version>
</dependency>

Controller

@RequestMapping(method = RequestMethod.POST, value = "/addEmployee", headers = "Accept=application/json")
    public @ResponseBody void addEmployee(
            @RequestHeader @Valid @RequestBody AddEmployeeBean requestBean,
            HttpServletRequest httpRequest) {.....}

Outer Bean - AddEmployeeBean

public class AddEmployeeBean {
    @Valid
    private EmployeeBean employeeBean;
    @NotEmpty
    private List<EmployeeBean> employeeDetails;
           |
           |
         getter- setter  
}

Inner Bean - EmployeeBean

public class EmployeeBean {
    @NotEmpty
    private String employeeId;
    @NumberFormat(style = Style.NUMBER)
    private long dept;
    @NumberFormat(style = Style.NUMBER)
    private long salary;
    @NotEmpty
    private String status;
           |
           |
         getter- setter 
}   
Community
  • 1
  • 1
vaibhav
  • 1
  • 3

1 Answers1

0

Check this for a solution for your problem. Hope it helps.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Aksanth
  • 269
  • 2
  • 13
  • According to link provided by you i have updated Outer bean as mentioned below , but now even if i am sending correct request payload its sending response as - "The request sent by the client was syntactically incorrect () -with Http status -400" - – vaibhav Aug 16 '16 at 13:04