Skip to content

Allow PropertyEditors to transform null values to alternative representation (empty Collection, empty array, domain specific NullObject, et cetera) [SPR-1729] #6426

@spring-projects-issues

Description

@spring-projects-issues

Taras Tielkes opened SPR-1729 and commented

The wide variation of domain models includes many flavors of representing null/nil members/relationships.

Among the various approaches are:
-Empty Collection members
-Empty array members
-Domain model specific NullObject pattern applications

We've been heavily using the PropertyEditor support in Spring MVC for binding directly to real domain model classes.
One of the missing (IMHO) pieces of functionality is more control over translating null values.

Scenario:
-Domain object has a member of type Collection (or subtype): for instance: the Roles assigned to a User
-Web form presents all possible selections, and indicates which are currently assigned (select multiple or a set of checkboxes)
-Controller class registers a CustomCollectionEditor for the "roles" property

When the form is submitted with all roles deselected, no HTTP parameters are sent. A common solution for this is to use the "field marker" support in WebDataBinder. This support adds a PropertyValue with value null to the current binding operation.

The current implemetation of BeanWrapperImpl has conditional blocks checking for a null value. In such a case, custom editors are never invoked.

This request comes down to giving registered editors a chance to process null values. Especially for editors like CustomCollectionEditor, being able to return an empty List, an empty Set or a NullObject instance would be a great improvement.


Affects: 1.2.6

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions