Bird
0
0

Find the problem in this code snippet:

medium📝 Debug Q7 of 15
Spring Boot - REST Controllers
Find the problem in this code snippet:
@GetMapping("/user")
public ResponseEntity getUser() {
    return "User data";
}
AURL path should be /users
BReturn type ResponseEntity requires a ResponseEntity object, not a String
CMissing @PostMapping annotation
DMethod should be private
Step-by-Step Solution
Solution:
  1. Step 1: Check return type and returned value

    The method declares return type ResponseEntity but returns a plain String.
  2. Step 2: Understand ResponseEntity usage

    ResponseEntity is a wrapper object; returning a String directly causes a type mismatch error.
  3. Final Answer:

    Return type ResponseEntity requires a ResponseEntity object, not a String -> Option B
  4. Quick Check:

    ResponseEntity return must match object type [OK]
Quick Trick: Return ResponseEntity object when declared as return type [OK]
Common Mistakes:
  • Returning String instead of ResponseEntity
  • Wrong URL path assumptions
  • Incorrect method visibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes