'"Required request body is missing: public org.springframework.http.ResponseEntity<?>
I am learning Spring-Boot features and going through them also with Postman. But when i run the code i get 400 Bad Request Error on Postman like this: "Required request body is missing: public org.springframework.http.ResponseEntity". Have i missed an attribute or the coding is all the way wrong?
@RestController
@RequestMapping("/api/board")
@CrossOrigin
public class ProjectTaskController {
@Autowired
private ProjectTaskService projectTaskService;
@PostMapping("")
public ResponseEntity<?> addPTToBoard( @Valid @RequestBody ProjectTask projectTask, BindingResult result){
if(result.hasErrors()) {
Map<String, String> errorMap= new HashMap<>();
for(FieldError error: result.getFieldErrors()) {
errorMap.put(error.getField(), error.getDefaultMessage());
}
return new ResponseEntity<Map<String, String>>(errorMap, HttpStatus.BAD_REQUEST);
}
ProjectTask newPT= projectTaskService.saveOrUpdateProjectTask(projectTask);
return new ResponseEntity<ProjectTask>(newPT, HttpStatus.CREATED);
}
The projectTask code, it has getters and setters also.
@Entity
public class ProjectTask {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
@NotBlank(message = "summary cannot be blank")
private String summary;
private String acceptanceCriteria;
private String status;
public ProjectTask() {
}
Postman request Here
Solution 1:[1]
Redi here's a sample request :
curl -X POST \
'http://>>>> your endpoint url' \
-H 'Content-Type: application/json' \
-d '{
"summary" : "sample summary",
"acceptanceCriteria" : "blabla",
"status" : "fake status"
}'
Solution 2:[2]
Since it is a @PostMapping you need to make a postman POST request like this:

make sure to select raw and content type of application/json along with a json object for the body of the request
Solution 3:[3]
That's right..! Yeah you are sending a bad request. You have to send request payload in POST request.
Solution : While sending the POST request please send with body like this in your case.
{
"summary":"any",
"acceptance":"any",
"status":"any"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nader.h |
| Solution 2 | |
| Solution 3 |
