Skip to content

java.util.Optional MultipartFile[] @RequestParam argument is null in multipart/form-data POST [SPR-15918] #20472

Closed

Description

@spring-projects-issues

Brice Roncace opened SPR-15918 and commented

If an Optional @RequestParam is not present in the request parameters, that value should be Optional.EMPTY as opposed to null. However, an Optional<MultipartFile[]> or Optional<List<MultipartFile>> parameter on a controller method handling a POSTed multipart/form-data request is NOT converting that parameter to Optional.EMPTY as expected but leaving it null.


Affects: 4.3.10

Reference URL: https://stackoverflow.com/q/45949393/225217

Issue Links:

Referenced from: commits 15c82af, 53a9697

Backported to: 4.3.12

Activity

  1. spring-projects-issues commented on Sep 20, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This turned out to be a general bug in the DefaultConversionService's CollectionToObjectConverter: It unconditionally turned an empty collection into null, not sending it through the ConversionService for potential Optional adaptation.

  2. spring-projects-issues commented on Dec 28, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Maciej Zerkowski commented

    Does it mean there is no way to get null instead of empty list for simple @RequestPart(required = false) List<MultipartFile> files rest controller method param?

  3. added
    type: bug
    status: backported
    on Jan 11, 2019
  4. added this to the 5.0 GA milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: backportedtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions