Bird
0
0

Given this code snippet inside a class extending ResponseEntityExceptionHandler:

medium📝 component behavior Q13 of 15
Spring Boot - Exception Handling
Given this code snippet inside a class extending ResponseEntityExceptionHandler:
  @Override
  protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
      String body = "Malformed JSON request";
      return new ResponseEntity<>(body, headers, HttpStatus.BAD_REQUEST);
  }
What will be the HTTP status code returned when a malformed JSON is sent to the API?
A200 OK
B500 Internal Server Error
C400 Bad Request
D404 Not Found
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the overridden method

    The method returns a ResponseEntity with status HttpStatus.BAD_REQUEST when JSON is malformed.
  2. Step 2: Identify the HTTP status code for BAD_REQUEST

    BAD_REQUEST corresponds to HTTP status code 400.
  3. Final Answer:

    400 Bad Request -> Option C
  4. Quick Check:

    BAD_REQUEST = 400 [OK]
Quick Trick: BAD_REQUEST means 400 status code [OK]
Common Mistakes:
  • Confusing BAD_REQUEST with 500 Internal Server Error
  • Assuming 200 OK is returned on error
  • Mixing up 404 Not Found with validation errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes