'Why is WebDataBinder RegisterCustomEditor ignoring the Field parameter

I'm writing an application using Spring Security Reactive and Spring WebFlux, which uses it's own binding implementation called WebExchangeDataBinder. I would like to encode passwords when new users sign up. I wrote a custom property editor for this, but it is only called if I remove the field designation from my InitBinder method--which is no good because then every String field in the User class is encoded.

@InitBinder
    public void initBinder (WebDataBinder binder) 
    {
        binder.registerCustomEditor(String.class,"password",encodingPropertyEditor);
    }

How can I run this editor ONLY for the "password" field of the User constructor?



Solution 1:[1]

Custom field binding at least in Reactive applications is impossible for immutable objects. This can be verified by stepping into the code and seeing that in

org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver on line 256 when binder.convertIfNecessary(value, paramTypes[i], methodParam) is called, the paramName value is not passed in. Then typeConverterDelegate.convertIfNecessary is called with a null propertyName and when propertyEditorRegistry.findCustomEditor(requiredType, propertyName) is finally called then of course the editor won't be found for the field.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shy Albatross