I have a rest API where I need to send page num as query parameter. When I send null, it gives me a bad request. Below is the rest API code
@RequestMapping(value = "/sample", method = RequestMethod.GET) @ResponseBody public String sample( @RequestParam(value = "page-number", required = false, defaultValue = "1") final Integer pageNumber, @RequestParam(value = "page-size", required = false, defaultValue = "50") final Integer pageSize) { return "hello"; } I am hitting the API with the following URL http://localhost:8000/sample?pageNumber=null
I am getting the below exception
"Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: \"null\"", How do I handle null case?
null, just remove the parameter from the URL .