I added a new object parameter to the RequestBody
of POST method. Below is the syntax of the method at controller:
public void registerTask(@RequestBody MyRequestDto myRequestDto)updated MyRequestDto class:private final String existing1;private final String existing2;private final NewParam myNewparam; // this is the new param that is added
the initialization is done through constructor:
public MyRequestDto(String existing1, String existing2, NewParam myNewparam){this.existing1 = existing1;this.existing2 = existing2;this.myNewparam = myNewparam;}
This is the new Param class definition:
public class NewParam { private final String name; public NewParam(String name) { this.name = name; } public String getName() { return name; }
The issue is when I send the tests through Postman by adding this NewParam
, I get 400 bad request. Following are the scenarios and the result:
- When the
NewParam
is not added to the request body. result- 201 is returned - When the
NewParam
is added, but the value is set as null. Result - 201 is returned.example:{"existing1": "test1","existing2": "test2","myNewparam": null}
- When the
NewParam
is added, and initialized to some value. result- 400 Bad Request (The request cannot be fulfilled due to bad syntax)example:{"existing1": "test1","existing2": "test2","myNewparam": {"name": "theme" }}
Note: the integration tests are also failing. While debugging the integration tests, the control is not going to controller, and only getting error as 400 Bad request.