Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
5.8.3
-
None
-
None
Description
As ValueEncoders are used to convert a parameter value to its actual type, only Boolean and Number-based types result directly in null for a blank value.
All other types use their TypeCoercer-based ValueEncoder, which not necessarily work.
However, I believe that if allowBlank = true is set, then a blank parameter should be able to lead to a null value.
Three possible changes come to mind to support blank --> null:
- Always treat blank as null before passing it the ValueEncoder
- Add boolean treatBlankAsNull() default false; to @RequestParameter, or
- adding String blankValue() String default ""; to @RequestParameter that is used instead of the parameter value if blank
Personally, I'd prefer the first option.
The TypeCoercedValueEncoderFactory would handle Boolean/Number just like before, but @RequestParamter wouldn't crash anymore if no valid coercion is possible for an empty String.
My proof-of-concept works and I might provide a feature branch soon.