Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring mvc empty array as a default value

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?

like image 925
user Avatar asked Feb 07 '13 11:02

user


1 Answers

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.

like image 153
user Avatar answered Nov 10 '22 07:11

user