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
ModelAttributeMethodArgumentResolver does not support custom field binding for immutable objects #28284
Comments
Hi @seabamirum, Thanks for creating your first issue for the Spring Framework. 👍 Is the behavior you are describing something that worked prior to 5.3.16? Also, please provide a simple application or test case that reproduces the behavior you are describing (for example, as a GitHub project or ZIP file attached to this issue that we can download and run locally). |
From a quick glance, it looks like we never supported this, taking the constructor parameter names into account for value retrieval but not for type conversion purposes. So only setter-derived property names are being exposed for PropertyEditor resolution, not constructor parameter names. We can certainly try to redefine this for exposing constructor parameter names there as well. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
I'm sorry I could not make a test case, because there's no straightforward way to get an instance of WebDataBinder without a target object that is already instantiated. However I think allowing custom property editors for constructor fields without setters would be a welcome improvement, if only for consistency in the framework. Right now it's not clear why it doesn't work, and I don't think it is documented. In my case I wanted to use a custom PasswordEncodingPropertyEditor to immediately encode the password in Spring Security's User object on signup. The only workaround that I found was to make a dummy object for binding, and then call the User.builder() method in the controller with the bound fields of that object. |
Supports name-bound PropertyEditor registrations on data classes. Includes consistent support for field-aware method parameters. Closes spring-projectsgh-28284
The
paramName
value for the constructor field is available, but is not used during binding on line 256 whenbinder.convertIfNecessary(value, paramTypes[i], methodParam)
is called. WhenpropertyEditorRegistry.findCustomEditor(requiredType, propertyName)
is finally called in theTypeConverterDelegate
, it is with a null value for thepropertyName
field, so any custom field editors will not be found.Affects: 5.3.16
The text was updated successfully, but these errors were encountered: