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 default value not set in certain cases [SPR-10180] #14813
Comments
Rossen Stoyanchev commented We can use the default value in those cases. Injecting null when a default value is specified doesn't make much sense. |
Michael Osipov commented Rossen, that makes sense but the general question is how should we treat such parameters (values) at all? What are these states? project?outputType => none given? |
Rossen Stoyanchev commented If a request parameter is present but is empty (i.e. "project?outputType" or "project?outputType="), type conversion turns the empty string into null. It doesn't seem to make much sense injecting null when the |
Michael Osipov commented What I would expect regardless the API does support that or not: Default value given and not required: No default value given and not required: No default value given and required: |
Rossen Stoyanchev commented
That would be useful if you want to validate that the client always provides a non-empty value or no value at all. Another application however might not care whether the value is empty or missing, and would expect the default value to be used always. Since there is no way to meet both of requirements, it would be good to make sure they can be achieved in some way. This is why I don't favor always raising an exception, which is in essence what you proposed. Instead if we tightened up the default value to be used for both empty and missing values, we'd get a single intuitive behavior for the default value, and if you wanted to treat empty values as an error, then you could remove the default value from |
Rossen Stoyanchev commented Moving to 3.2.2 to allow more time for comments. |
Rossen Stoyanchev commented Changing to 'Improvement'. The current behavior is a special case for which the behavior is not well defined rather than a bug. |
Michael Osipov commented Rossen, yes your argumentation makes sense. I would accept your proposed behavior as a good choice. How would you comment on the last case? Would agree? I any way, we would have a clear/uniform behavior how edge cases would be treated. |
Michael Osipov commented Thanks for the fix. Are you able to reflect this change in the |
Rossen Stoyanchev commented Yes, thanks for the reminder. |
Michael Osipov opened SPR-10180 and commented
I have this
@RequestMapping
Where
OutputType
is an enum with the values HASH and ARRAY.In the following edge cases:
The
outputType
variable is not populated with the default value but anull
is assigned. TheRequestParamMethodArgumentResolver
receives this as an empty string.See the attached screenshot of the debugger.
If this cannot be reasonable fixed, add at least a paragraph to the docs that such edge cases exist.
Affects: 3.1.3, 3.2 GA
Attachments:
Referenced from: commits 3abe05c, 221562d
The text was updated successfully, but these errors were encountered: