Spring empty mvc array as default

I have a spring controller method that receives some optional arrays as parameters. They are not required, but I would like them not to be empty, but only empty arrays, when they are, are not in the parameters obtained by the controller method. I know, I could test them for being null and then assign them as a new object, but this will create a lot of patterns. 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 get the 400th error when I do not provide the parameter in the url, which is strange because the required field is false.

Any ideas on this guys?

+5
source share
1 answer

. - "". , , 400- . Weird. .

+7

All Articles