0
0
Spring Bootframework~10 mins

@RequestBody for JSON input in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to accept JSON input in a Spring Boot controller method.

Spring Boot
public ResponseEntity<String> createUser([1] User user) {
    // method body
}
Drag options to blanks, or click blank then click option'
A@PathVariable
B@RequestParam
C@RequestBody
D@Autowired
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PathVariable instead of @RequestBody
Forgetting to annotate the parameter
2fill in blank
medium

Complete the code to specify the HTTP method and path for JSON input handling.

Spring Boot
@[1]("/users")
public ResponseEntity<String> addUser(@RequestBody User user) {
    // method body
}
Drag options to blanks, or click blank then click option'
AGetMapping
BPostMapping
CDeleteMapping
DPutMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetMapping which does not support request body
Using DeleteMapping or PutMapping incorrectly
3fill in blank
hard

Fix the error in the method parameter to correctly receive JSON input.

Spring Boot
public ResponseEntity<String> updateUser([1] user) {
    // method body
}
Drag options to blanks, or click blank then click option'
AUser
B@PathVariable User
C@RequestParam User
D@RequestBody User
Attempts:
3 left
💡 Hint
Common Mistakes
Missing @RequestBody annotation
Using @RequestParam or @PathVariable incorrectly
4fill in blank
hard

Fill both blanks to create a controller method that accepts JSON and returns a response.

Spring Boot
@[1]("/products")
public ResponseEntity<[2]> addProduct(@RequestBody Product product) {
    // method body
}
Drag options to blanks, or click blank then click option'
APostMapping
BGetMapping
CProduct
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetMapping for JSON input
Returning the Product object instead of a response message
5fill in blank
hard

Fill all three blanks to define a Spring Boot controller method that accepts JSON, validates it, and returns a response.

Spring Boot
@[1]("/orders")
public ResponseEntity<[2]> placeOrder(@Valid @RequestBody [3] order) {
    // method body
}
Drag options to blanks, or click blank then click option'
APostMapping
BString
COrder
DGetMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetMapping instead of PostMapping
Missing @RequestBody or @Valid annotations
Wrong return type