Search code examples
springspring-mvcspring-testspring-web

Spring 4 Optional<List<String>> @RequestParam


Using java.util.Optional as a spring controller request parameter.

For simple values (int, String, etc) it works as expected but for a parameter which is of type List<String> or String[] and for which I pass multiple values:

    mockMvc.perform(get("/get").param("param", "value1", "value2"))

it always picks just one value of the passed ones.

@RequestMapping(value = "/get", method = RequestMethod.GET)
public Object get(@RequestParam(name = "param") Optional<String[]> array) {
    // the array will have just 1 element : 'value1'
}

Solution

  • this issue will be resolved in next spring web release 4.3 https://jira.spring.io/browse/SPR-13418