Skip to content

Handling of spaces and underscores in AbstractBeanPropertyRowMapper [SPR-5758] #10428

Closed
@spring-projects-issues

Description

@spring-projects-issues

Pablo Krause opened SPR-5758 and commented

The class AbstractBeanPropertyRowMapper can handle underscores for matching column names to property names in a Bean, but not spaces.
I tested with a very simple patch, which consisted of chanching line 109 from:

PersistentField fieldMeta = (PersistentField) this.mappedFields.get(column);
to
PersistentField fieldMeta = (PersistentField) this.mappedFields.get(column.replaceAll(" |_", ""));

This simple change allows to match database columns either with underscores or spaces in their names with the corresponding java bean properties.
As a matter of fact, this patch makes the use of the underscoreName() method in that same class obsolete, as well as lines 202-205 in which names with and without underscores are set in the mappedFields map (I don't understand why you took this approach instead of stripping the underscores in line 109... perfomance?).

I know this is probably of use to nearly no one, but I am dealing with some legacy stored procedures which return column names with spaces so I decided to try to contribute something back.


Affects: 2.5 final, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6

Referenced from: commits 8079262

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions