I have an endpoint which receives a JSON through POST request.
RequestMapping(value = "/app/login", method = RequestMethod.POST,
headers = { "Content-type=application/json" })
@ResponseBody
public LoginResponse logIn(@RequestBody LoginRequest jsonRequest) {
// code
}
LoginRequest:
public class LoginRequest {
private String user;
private String password;
private String idPush;
private Integer idDevice;
// getters and setters
}
Is there anyway I can specify idDevice as optional?
If I don't send idDevice inside the json, Spring returns a 400 error.
It seems that setting the RequestBody to optional, makes any property optional, not only the full bean.
public LoginResponse logIn(@RequestBody(required=false) LoginRequest jsonRequest) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With