Allow empty list for @RequestPart List<MultipartFile> #352
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have a use case where I need to send a list of
MultipartFile
s, but sometimes this list could be empty. Currently, to successfully send an empty list (i.e. the server receives an empty list as a method argument), I need to sendnull
instead, which requires me to do a priorisEmpty()
check.(It is strange that sending
null
from the client results in an empty list received by the server, but this is documented here.)Sending an empty list now throws an exception:
This PR adds an
EmptyCollectionWriter
toMultipartFormContentProcessor
in theSpringFormEncoder
. ThisWriter
is a no-op.It would be ideal to add the
EmptyCollectionWriter
in the feign-form project instead, but that project is relatively inactive.I also added a new test client endpoint that counts the number of files sent, to make sure that empty lists are not received as
null
, in case Spring Framework changes behaviour in the future.