Bird
0
0

You want your Spring Boot API to support JSON, XML, and YAML responses based on client request. Which configuration is correct?

hard📝 Application Q8 of 15
Spring Boot - Request and Response Handling
You want your Spring Boot API to support JSON, XML, and YAML responses based on client request. Which configuration is correct?
A@GetMapping(value = "/item", produces = "application/json")
B@GetMapping(value = "/item", consumes = {"application/json", "application/xml", "application/x-yaml"})
C@GetMapping(value = "/item", produces = {"application/json", "application/xml", "application/x-yaml"})
D@GetMapping(value = "/item", headers = {"Accept=application/json", "Accept=application/xml", "Accept=application/x-yaml"})
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct attribute for response formats

    'produces' defines supported response content types.
  2. Step 2: Check for multiple formats support

    Using an array with JSON, XML, and YAML is correct for content negotiation.
  3. Final Answer:

    @GetMapping(value = "/item", produces = {"application/json", "application/xml", "application/x-yaml"}) -> Option C
  4. Quick Check:

    Multiple response types = produces with array [OK]
Quick Trick: Use 'produces' with array to support multiple formats [OK]
Common Mistakes:
  • Using 'consumes' instead of 'produces'
  • Using headers attribute incorrectly
  • Limiting to only JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes