Performance: Problem Details for standard error format
This affects the speed and clarity of error responses, impacting user experience and API responsiveness.
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ProblemDetail.forStatus(HttpStatus.BAD_REQUEST).withDetail("Invalid input"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Error: Invalid input");
| Pattern | Serialization Cost | Client Parsing | Network Payload | Verdict |
|---|---|---|---|---|
| Plain string error | Low | High (manual parsing) | Small | [X] Bad |
| Standard ProblemDetail JSON | Moderate | Low (automatic parsing) | Slightly larger | [OK] Good |
ResourceNotFoundException is thrown?
@RestController
public class MyController {
@GetMapping("/item/{id}")
public Item getItem(@PathVariable String id) {
throw new ResourceNotFoundException("Item not found");
}
}type field in a Problem Details response for a specific exception in Spring Boot?Pass the test and this pattern moves unknown