You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support to be able to easily configure a DataClassRowMapper when using JdbcCursorItemReaderBuilder & JdbcPagingItemReaderBuilder - similar to the existing beanRowMapper functionality added in #895 and #819. This would make it easier to set up jdbc item readers when the target class is a Java record or Kotlin data class.
One approach could be to modify the existing JdbcCursorItemReaderBuilder::beanRowMapper & JdbcPagingItemReaderBuilder::beanRowMapper methods to set a DataClassRowMapper instead of a BeanPropertyRowMapper - according to the docs it is backwards compatible.
Note that this class extends BeanPropertyRowMapper and can therefore serve as a common choice for any mapped target class, flexibly adapting to constructor style versus setter methods in the mapped class.
A second approach could be to add new builder methods JdbcCursorItemReaderBuilder::dataRowMapper & JdbcPagingItemReaderBuilder::dataRowMapper that create and set a DataClassRowMapper.
will create item readers w/ a BeanPropertyRowMapper. From the docs:
If you need to map to a target class which has a data class constructor — for example, a Java record or a Kotlin data class — use DataClassRowMapper instead.
Context
As we convert batch jobs to use java record classes, we find ourselves needing to change .beanRowMapper(Foo.class) -> .rowMapper(new DataClassRowMapper<>(FooRecord.class)) over and over again.
Thank you for your suggestion, that's a good idea! Since Java beans and records are different, I think it makes more sense to have different methods in the builders.
Expected Behavior
Add support to be able to easily configure a
DataClassRowMapper
when usingJdbcCursorItemReaderBuilder
&JdbcPagingItemReaderBuilder
- similar to the existingbeanRowMapper
functionality added in #895 and #819. This would make it easier to set up jdbc item readers when the target class is a Javarecord
or Kotlindata
class.One approach could be to modify the existing
JdbcCursorItemReaderBuilder::beanRowMapper
&JdbcPagingItemReaderBuilder::beanRowMapper
methods to set aDataClassRowMapper
instead of aBeanPropertyRowMapper
- according to the docs it is backwards compatible.A second approach could be to add new builder methods
JdbcCursorItemReaderBuilder::dataRowMapper
&JdbcPagingItemReaderBuilder::dataRowMapper
that create and set aDataClassRowMapper
.If there is a preferred approach, please let me know and I will be happy to try to contribute a PR for the changes! 🤓
Current Behavior
and
will create item readers w/ a
BeanPropertyRowMapper
. From the docs:Context
As we convert batch jobs to use java
record
classes, we find ourselves needing to change.beanRowMapper(Foo.class)
->.rowMapper(new DataClassRowMapper<>(FooRecord.class))
over and over again.Might be similar to #4160, #4568
The text was updated successfully, but these errors were encountered: