Spring Boot - Request and Response HandlingWhich of the following is the correct way to specify JSON response in a Spring Boot controller method?A@GetMapping(value = "/data", consumes = "application/json")B@GetMapping(value = "/data", produces = "application/json")C@PostMapping(value = "/data", produces = "text/html")D@RequestMapping(value = "/data", method = GET, consumes = "text/plain")Check Answer
Step-by-Step SolutionSolution:Step 1: Understand 'produces' vs 'consumes''produces' defines the response content type; 'consumes' defines the request content type.Step 2: Identify correct annotation for JSON response@GetMapping with produces = "application/json" tells Spring Boot to send JSON data in response.Final Answer:@GetMapping(value = "/data", produces = "application/json") -> Option BQuick Check:produces = JSON means response is JSON [OK]Quick Trick: Use 'produces' to set response format [OK]Common Mistakes:Mixing 'consumes' with response content typeUsing wrong HTTP method annotationSetting produces to unrelated content types
Master "Request and Response Handling" in Spring Boot9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Spring Boot Quizzes Application Configuration - application.properties structure - Quiz 2easy Inversion of Control and Dependency Injection - Field injection and why to avoid it - Quiz 12easy Logging - Logger creation in classes - Quiz 13medium REST Controllers - @PutMapping and @DeleteMapping - Quiz 15hard REST Controllers - @RequestBody for JSON input - Quiz 11easy Request and Response Handling - Returning different status codes - Quiz 5medium Spring Annotations - @Profile for environment-specific beans - Quiz 2easy Spring Annotations - @Configuration and @Bean - Quiz 4medium Spring Boot Fundamentals - Why Spring Boot over plain Spring - Quiz 10hard Spring Boot Fundamentals - Embedded server concept - Quiz 7medium