-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@RequestParam
binding does not support params with an empty array "[]" suffix
#32577
Comments
Do they? I can see this being used in PHP but that's an implementation detail that's not backed by anything I am aware of in a spec. If you need to pass multiple values, you should use the attribute as requested and let the server rebuild the list for you. |
then why do you support this format here? Special DataBinder for data binding from web request parameters to JavaBean objects org.springframework.web.bind.WebDataBinder#adaptEmptyArrayIndices Check for property values with names that end on "[]". This is used by some clients for array syntax without an explicit index value. If such values are found, drop the brackets to adapt to the expected way of expressing the same for data binding purposes. |
I wasn't aware we did. That's a question for @rstoyanchev then See #25836 (comment) |
Our situation is further complicated by the following: we use the open api to describe the contract, and the openapi-generator to generate the client and controller interfaces. this means that even if we consider this option (from the link to the issue that you provided)
there are two disadvantages to this solution:
|
Indeed I think this is the the equivalent of #25836 but for |
@RequestParam
binding does not support params with an empty array "[]" suffix
Affects: 2.5.2
Many http clients pass an array to queryString in this form:
?attributes[]=field1&attributes[]=field2
I'm trying to get Controller to work with this format through RequestParam:
However, when executing a request, null is passed to the controller method as the attributes value.
I found that the "RequestParamMethodArgumentResolver.resolveName" method receives "attributes" as the value of the parameter name, while this parameter is stored in the request object using the key "attributes[]". Therefore, the argument of the controller method is null, because resolver cannot find a match.
How would you like to add such support to RequestParamMethodArgumentResolver? The code could look something like this:
In my project, I replaced the built-in RequestParamMethodArgumentResolver with a custom one. An example can be found in the description of the question on stackoverflow
The text was updated successfully, but these errors were encountered: