0 day streak
java / beginner
Snippet

Receiving JSON Data with @RequestBody

The @RequestBody annotation tells Spring to deserialize the incoming JSON request body into a Java object.

snippet.java
java
1
2
3
4
@PostMapping("/api/submit")
public String process(@RequestBody Feedback feedback) {
return "Received feedback from: " + feedback.getEmail();
}
spring
Breakdown
1
@PostMapping("/api/submit")
Handles HTTP POST requests for creating or processing data.
2
@RequestBody Feedback feedback
Converts the JSON body into a 'Feedback' object.