Fakipo
Fakipo

Reputation: 190

How to send both object and parameters in postman?

I want to send an object of arraylist(in java) and other parameters as passed by the user to postman.

Here is my Code for controller

        @PostMapping(path = "/listEmpPaidSalariesPaged", produces = "application/json")

        public List<EmployeeSalaryPayment> listEmpPaidSalariesPaged
        (long SID, Collection<Student> student, String orderBy,
        int limit, int offset)

I know you can use RAW data and JSON for object and x-www-form-urlencoded for parameters, but how to send them together?

Upvotes: 0

Views: 1027

Answers (1)

Henrique Forlani
Henrique Forlani

Reputation: 1353

You can use @RequestBody and @RequestParam annotations, like for example:

@PostMapping(path = "/listEmpPaidSalariesPaged", produces = "application/json")
public List<EmployeeSalaryPayment> listEmpPaidSalariesPaged(@RequestBody StudentRequestModel studentRequestModel, @RequestParam(value = "orderBy", defaultValue = "descending") String orderBy, @RequestParam(value = "limit", defaultValue = "25") int limit, @RequestParam(value = "offset", defaultValue = "0") int offset) {
       // controller code
}

@RequestBody will automatically deserialize the HttpRequest body (raw JSON from postman) into a java object (StudentRequestModel). @RequestParam will extract your query parameters (in postman you can do a POST to /listEmpPaidSalariesPaged?orderBy=ascending for example) into the defined variables. You can do both at the same time of course in postman.

Upvotes: 1

Related Questions