ARTICLE AD BOX
I am working on a Spring Boot application where I am trying to save a Question entity using a POST API. However, whenever I send a JSON request from Postman, I receive 400 Bad Request.
I expected the request to be processed successfully and the data to be saved in the database.
Controller
@RestController @RequestMapping("/api/questions") public class QuestionController { @Autowired private QuestionService questionService; @PostMapping public ResponseEntity<Question> createQuestion(@RequestBody Question question) { return ResponseEntity.ok(questionService.save(question)); } }Entity
@Entity public class Question { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String title; private String content; // getters and setters }JSON Request (Postman)
{ "title": "How to handle exceptions in Spring Boot?", "content": "I want to know the best practices for exception handling." }Error
400 Bad Request Required request body is missingWhat I Have Tried
Ensured @RequestBody is present
Verified JSON format
Checked Content-Type: application/json
Restarted the application
Enabled logging
But the issue still persists.
Environment
Spring Boot: 3.x
Java: 17
OS: Ubuntu
Postman latest version
