Skip to content

Request parameters cannot bind to Optional<List<String>> [SPR-13418] #17997

Closed
@spring-projects-issues

Description

@spring-projects-issues

Kazuki Shimizu opened SPR-13418 and commented

Request parameter cannot bind to Optional<List<String>> at the @RequestMapping method.

I define the following method as handler method(@RequestMapping method).

@RequestMapping(path="search")
public String search(@RequestParam(defaultValue="word1,word2,word3") Optional<List<String>> words, Model model) {
    List<String> searchWords = words.get();
    System.out.println(searchWords);
    //...
}

I submit a request to http://localhost:8080/myApp/search?words=aaa&words=bbb.
In this case, i was expected a printing as follow:

[aaa, bbb]

But actually, printed as follow:

[aaa]

In this case, request parameters can be bind to first element only.

In addition, i submit a request to http://localhost:8080/myApp/search. (without request parameters)
In this case, printed as follow:

[word1, word2, word3]

In this case,default value converted by conversion service was applied.

This behavior is bug or specification ?

I will submit a repro project at the later.


Affects: 4.2.1

Issue Links:

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions