-
Notifications
You must be signed in to change notification settings - Fork 356
Custom converter not used for Iterable type from 2.4.1 #1343
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
In fact, the implementation of an In all these cases, the else block must be executed. The object is written with an attempt to find a custom converter: jdbcValue = converter.writeJdbcValue(value, type,
JdbcUtil.targetSqlTypeFor(JdbcColumnTypes.INSTANCE.resolvePrimitiveType(type))); As a solution, i can propose additional check method: private boolean isGenericIterable(ResolvableType resolvableType, Object value) {
return resolvableType.hasGenerics() && value instanceof Iterable;
} So the code will look like this: private void convertAndAddParameter(MapSqlParameterSource parameters, Parameter p, Object value) {
// ..............
ResolvableType resolvableType = parameter.getResolvableType();
// ..............
JdbcValue jdbcValue;
if (isGenericIterable(resolvableType, value)) {
// ..............
} else {
// ..............
}
} |
Fix to check for both iterable and hasGenerics before proceeding
Fix to check for both iterable and hasGenerics before proceeding
Hi @loolzaaa, |
#1323 has issues with the same change, so I think this change would not be everything - it needs to have a generic, but the generic also needs to be a primitive type, I think. |
Actually,
If we exclude the last check that the data is binary, then the final representation (see next) in sql query of the When Spring create prepared statement, it substitute named parameters. If the parameter itself is iterable, then each of its elements will be wrapped in brackets So, i think iterable condition above must satisfy the following conditions:
As a solution, i can propose updated additional check method: private boolean isNonArrayGenericIterable(ResolvableType resolvableType, Object value) {
boolean typeHasGenerics = resolvableType.hasGenerics();
if (typeHasGenerics) {
Class<?> elementType = resolvableType.getGeneric(0).resolve();
return value instanceof Iterable && !elementType.isArray();
}
return false;
} |
Contents of Iterables that aren't collections will not be converted individually. Closes #1343
Contents of Iterables that aren't collections will not be converted individually. Closes #1343
Contents of Iterables that aren't collections will not be converted individually. Closes #1343
I have a custom converter
JsonNode <-> PGobject
(PGobject represent JSON type for PostgreSQL):Also, i have a simple repo
@Query
method:Before Spring Data JDBC this converter used normally: old version of code
But, from 2.4.1 version there is a check for
Iterable
inStringBasedJdbcQuery
:JsonNode
implementsIterable
interface, butClass<?> elementType
is null, so assert is failed and custom converter never applied. If manually run else block, conversion goes normally.The text was updated successfully, but these errors were encountered: