Performance: @RequestBody for JSON input
MEDIUM IMPACT
This affects the server-side processing time and the responsiveness of the API endpoint when receiving JSON data.
@PostMapping("/data") public ResponseEntity<String> receiveData(@RequestBody Data data) { // Spring automatically parses JSON to Data object // process data return ResponseEntity.ok("Received"); }
@PostMapping("/data") public ResponseEntity<String> receiveData(@RequestBody String json) throws IOException { // Manually parse JSON string ObjectMapper mapper = new ObjectMapper(); Data data = mapper.readValue(json, Data.class); // process data return ResponseEntity.ok("Received"); }
| Pattern | CPU Usage | Parsing Overhead | Latency Impact | Verdict |
|---|---|---|---|---|
| Manual JSON parsing in controller | High | High | Increases latency | [X] Bad |
| @RequestBody automatic JSON binding | Low | Low | Minimal latency impact | [OK] Good |