How can I make a Spring @Controller
return a 400
status code if the client sends any unexpected request parameters?
For example, I have this
public ResponseEntity<String> recommend(
@RequestParam(value = "max-age-seconds", required = false) Long maxAgeSeconds) {
...
}
And the client may have a typo in max-age-seconds
, which my application won't recognise and then fallback to the default max age I chose at a later time.
I know I could get the list of all the request parameters with request.getParameterNames()
and check one by one, but I'm looking for a neater and more efficient solution.
EDIT: I just found out that 4 years ago it didn't have a built-in solution, I wonder if it's still the case.