Browse Source

Merge 3f735def5f into 4890a5556f

pull/2218/merge
tamland 1 week ago committed by GitHub
parent
commit
a57fb5bc7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java
  2. 11
      spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java

14
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java

@ -21,6 +21,7 @@ import static org.assertj.core.api.SoftAssertions.*; @@ -21,6 +21,7 @@ import static org.assertj.core.api.SoftAssertions.*;
import java.math.BigDecimal;
import java.sql.JDBCType;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
@ -182,6 +183,19 @@ public class JdbcRepositoryCustomConversionIntegrationTests { @@ -182,6 +183,19 @@ public class JdbcRepositoryCustomConversionIntegrationTests {
assertThat(reloaded).isEqualTo(saved);
}
@Test
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_ARRAYS)
void saveAndLoadListOfNullAsArray() {
var list = new ArrayList<Direction>();
list.add(null);
EntityWithDirections saved = repositoryWithDirections.save(new EntityWithDirections(null, list));
EntityWithDirections reloaded = repositoryWithDirections.findById(saved.id).orElseThrow();
assertThat(reloaded).isEqualTo(saved);
}
interface EntityWithStringyBigDecimalRepository extends CrudRepository<EntityWithStringyBigDecimal, CustomId> {
@Query("SELECT * FROM ENTITY_WITH_STRINGY_BIG_DECIMAL WHERE DIRECTION IN (:types)")

11
spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java

@ -812,16 +812,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter @@ -812,16 +812,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter
return mapped;
}
// if we succeeded converting the members of the collection, we actually ignore the fallback targetType since that
// was derived without considering custom conversions.
Class<?> targetType = type.getType();
if (!mapped.isEmpty()) {
Class<?> targetComponentType = mapped.get(0).getClass();
targetType = Array.newInstance(targetComponentType, 0).getClass();
}
Object converted = getConversionService().convert(mapped, targetType);
Object converted = getConversionService().convert(mapped, type.getType());
Assert.state(converted != null, "Converted must not be null");

Loading…
Cancel
Save