This maybe a simple question but I couldn't figure it out myself nor could I find an online resource for it.
I have to develop a REST API using spring boot. I see two options to accept the json payload (max payload size 3 MB in some cases)
Option 1: Ask clients to send json in request body. Let Jackson convert it to Java object
@RestController
public class EmployeeController {
@PostMapping
public void createEmployees(@RequestBody List<Employee> employees) {
// do something with employees
}
}
Option 2: Ask clients to upload a json file and let the controller accept Multipart payload
@RestController
public class EmployeeController {
@PostMapping(consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public void createEmployees(@RequestParam(name = "file") MultipartFile file) {
// convert multipart file data to List of Employee objects
//do something with employees
}
}
Which option is better and why?