Bird
0
0

Identify the error in this method signature:

medium📝 Debug Q6 of 15
Spring Boot - REST Controllers
Identify the error in this method signature:
@PostMapping("/add")
public void addUser(@RequestBody String userJson) {
  User user = new User();
  // missing JSON parsing
}
AMissing JSON parsing from userJson to User object
BIncorrect HTTP method for @RequestBody
C@RequestBody cannot be used with String type
DMethod should return User object
Step-by-Step Solution
Solution:
  1. Step 1: Check how JSON is handled

    The method receives JSON as a String but does not convert it to User object.
  2. Step 2: Identify missing step

    Without parsing userJson, the User object remains empty and unusable.
  3. Final Answer:

    Missing JSON parsing from userJson to User object -> Option A
  4. Quick Check:

    Must parse JSON string to object manually [OK]
Quick Trick: Parse JSON string to object if using String with @RequestBody [OK]
Common Mistakes:
  • Assuming Spring auto-parses String to object
  • Using wrong HTTP method
  • Expecting return type mismatch to cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes