-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Give JdbcClient
access to ConversionService
for converting custom database object types
#33467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
for anyone else struggling with this the solution was to add the jdbc driver for your database to the compilation scope (e.g. from runtimeClasspath to implementation in gradle terms) and simply refer the types in the jdbc driver in your record/classes for fetching. a conversion service for the jdbcclient would still be an improvement though, im not sure using types from a jdbc driver is a great choice. |
It requires changes both in Spring Framework (construct jdbcClient.sql("select jsonb_column from some_table").query(new SimplePropertyRowMapper<>(CustomRecord.class, conversionService)).list(); |
If this issue is waiting for feedback from me, I would just say that it appears part of the plumbing is already there, so I am just trying to improve the wiring. clearly the responsibility of the client is to return pojos, which includes conversion. why not support conversion from the spring framework? this preserves the typical responsibility of framework to do, and boot to configure. |
We have discussed it as a team and here is our assessment: From a Spring Framework perspective, this would indeed mean adding constructor variants for From a Spring Boot perspective, we don't think that we should change the auto-configuration there, as there is a default conversion service used for binding properties, another one for the web parts of the application, and possibly more... Instead, we think that the users can create a custom We are declining this enhancement from a Spring Boot perspective, and transferring this issue to the Framework team so they can consider this request. Thanks! |
JdbcClient
access to ConversionService
for converting custom database object types
Enhancement Description: allow JdbcClient to convert custom object types in records. for example, in postgres you may have a jsonb and you'd want to be able to convert that into something so that you can parse it onto your record class while fetching:
code references:
spring-framework/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java
Lines 199 to 206 in d2ea5b4
spring-framework/spring-jdbc/src/main/java/org/springframework/jdbc/core/SimplePropertyRowMapper.java
Lines 92 to 120 in d2ea5b4
possible solution:
from their current form
to this pattern:
to
benefits
you can now register converters as beans and they will be able to be used for jdbcClient queries.
considerations
java.util.Objects.requireNonNullElseGet(conversionService, DefaultConversionService::getSharedInstance)
.The text was updated successfully, but these errors were encountered: