I have a spring controller method that receives some optional arrays as parameters. They are not required, but I'd like them to be not null, but just empty arrays when they are are not in the parameters which are received by the controller method. I know, I could check them for being null and then assign as new object, but that would generate lots of boilerplate code. Also, when I try to do something like this:
@RequestMapping(headers = "Accept=application/json", method = RequestMethod.GET, value = "/socialUsers/saveFilter", produces = "application/json")
public @ResponseBody
void saveFilterToDataBase(@RequestParam(required = false, value = "gender", defaultValue = "{}") Gender[] genders)
....
I receive the 400th error, when I don't provide the parameter in the url, which is weird, cause the required field is false.
Any ideas on that, guys?
Found the solution. The default empty array value is just "". But the problem is that even though the parameter is not required, it throws the 400th error. Weird. Working on that.
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