To get list of objects via @RequestBody
in controller and process each object in a list
to do a business logic.
I have tried this but not working
@RequestMapping(value="/updateservicetype", method=RequestMethod.POST,produces="application/json")
public @ResponseBody ServiceTypesMessage updateServiceType(@RequestBody List<BarberServiceType> serviceTypes,final HttpServletResponse response){
also tried following:
@RequestMapping(value="/updateservicetype", method=RequestMethod.POST,produces="application/json")
public @ResponseBody ServiceTypesMessage updateServiceType(@RequestBody BarberServiceType[] serviceTypes,final HttpServletResponse response){
Below works for me
@RequestMapping(value = "/payments", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Payment> batchCreate(@RequestBody List<Payment> payments) {
return paymentService.create(payments);
}
You will need Jackson in the class path
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
Json in put is
[{"sort":"10-20-30","account":"1234"},{"sort":"10-20-30","account":"1234"}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With