spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

BeanPropertyRowMapper's support for direct column name matches is missing in DataClassRowMapper

Open madorb opened this issue 3 years ago • 0 comments

This is a follow-on to closed ticket (that i'm unable to reopen) which I believe, did not fully address the problem.

After the update the BeanPropertyRowMapper's behavior still does not match the documentation from BeanPropertyRowMapper which states:

The names are matched either directly or by transforming a name separating the parts with underscores to the same name using "camel" case.

The "directly" part of the mapping does not occur, instead it only attempts to match fully lower-cased values.

Given data class:

data class MyClass(
    @Id
    val someId: Long?,
    val fooValue String?,
    val barValue: String?,
    val updateTimestamp: LocalDateTime?
)

and query:

SELECT someId, fooValue, barValue, updateTimestamp FROM ...

the fields are not mapped.

Mapping happens successfully if either the query is changed to:

SELECT someId as some_id, fooValue as foo_value, barValue as bar_value, updateTimestamp as update_timestamp FROM ...

OR the data class is changed to:

data class MyClass(
    @Id
    val someid: Long?,
    val foovalue String?,
    val barvalue: String?,
    val updatetimestamp: LocalDateTime?
)

It seems either the documentation or the behavior of this class should be changed.

madorb avatar Sep 21 '22 22:09 madorb