spring-projects / spring-projects/spring-framework
Allow null handling with @InitBinder & PropertyEditor/Converter/Formatter to handle null values.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
With @InitBinder it is currently possible to register various property handlers to customize the web request data binding via binder.registerCustomEditor(Class<?>, String, PropertyEditor), binder.addCustomFormatter(Formatter<?>, String...) or using a Converter.
However none of these get called if the property is absent from the request.
I don't know if this is a bug or desired behavour, but there should be at least the possibility to handle such cases.
Current Behavior
Neither registered PropertyEditor nor Formatter nor Converter get invoked when a property is missing from the request. That is it only works if the property is explicitly sent as `null in the request.
Desired Behavior
Allow for PropertyEditor / Formatter / Converter to get called if an Optional/@Nullableproperty is absent from the request. And not just when explicitely sent asnull.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Spring MVC request data binding and the @InitBinder registration points named in the issue: registerCustomEditor, addCustomFormatter, and Converter handling. Reproduce a request where an Optional or @Nullable property is absent, then compare it with an explicit null value. Done means the registered PropertyEditor, Formatter, or Converter can handle the absent-property case without changing existing binding behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100