Bird
0
0

If a Spring Boot controller method is annotated with @GetMapping(produces = "application/json") and the client sends Accept: text/html, what will happen?

medium📝 component behavior Q5 of 15
Spring Boot - Request and Response Handling
If a Spring Boot controller method is annotated with @GetMapping(produces = "application/json") and the client sends Accept: text/html, what will happen?
ASpring Boot returns JSON anyway
BSpring Boot returns HTTP 406 Not Acceptable
CSpring Boot returns HTML format
DSpring Boot ignores Accept header and returns XML
Step-by-Step Solution
Solution:
  1. Step 1: Check produces and Accept header mismatch

    The method only produces JSON but client wants HTML.
  2. Step 2: Understand Spring Boot behavior on mismatch

    Spring Boot responds with HTTP 406 error when no matching format is found.
  3. Final Answer:

    Spring Boot returns HTTP 406 Not Acceptable -> Option B
  4. Quick Check:

    Mismatch Accept and produces = 406 error [OK]
Quick Trick: No matching format causes 406 Not Acceptable error [OK]
Common Mistakes:
  • Assuming server returns default JSON anyway
  • Thinking server converts formats automatically
  • Ignoring HTTP 406 error possibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes