Skip to content

Commit 0694321

Browse files
vgalloyschauder
authored andcommitted
Fix Enum[] type conversion.
Since 3.0.5, Enum[] type are detect as "UNKNOWN" Closes #1460 Original Pull request #1521
1 parent 8545061 commit 0694321

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,16 @@ void insertOnlyPropertyDoesNotGetUpdated() {
10451045
assertThat(template.findById(entity.id, WithInsertOnly.class).insertOnly).isEqualTo("first value");
10461046
}
10471047

1048+
@Test // GH-1460
1049+
void readEnumArray() {
1050+
EnumArrayOwner entity = new EnumArrayOwner();
1051+
entity.digits = new Color[]{Color.BLUE};
1052+
1053+
assertThat(template.save(entity)).isNotNull();
1054+
1055+
assertThat(template.findById(entity.id, EnumArrayOwner.class).digits).isEqualTo(new Color[]{Color.BLUE});
1056+
}
1057+
10481058
private <T extends Number> void saveAndUpdateAggregateWithVersion(VersionedAggregate aggregate,
10491059
Function<Number, T> toConcreteNumber) {
10501060
saveAndUpdateAggregateWithVersion(aggregate, toConcreteNumber, 0);
@@ -1086,6 +1096,17 @@ private Long count(String tableName) {
10861096
return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM " + tableName, emptyMap(), Long.class);
10871097
}
10881098

1099+
enum Color {
1100+
BLUE
1101+
}
1102+
1103+
@Table("ARRAY_OWNER")
1104+
private static class EnumArrayOwner {
1105+
@Id Long id;
1106+
1107+
Color[] digits;
1108+
}
1109+
10891110
@Table("ARRAY_OWNER")
10901111
private static class ArrayOwner {
10911112
@Id Long id;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public Object writeValue(@Nullable Object value, TypeInformation<?> type) {
175175

176176
// TODO: We should add conversion support for arrays, however,
177177
// these should consider multi-dimensional arrays as well.
178-
if (value.getClass().isArray() && (TypeInformation.OBJECT.equals(type) || type.isCollectionLike())) {
178+
if (value.getClass().isArray() && !value.getClass().getComponentType().isEnum() && (TypeInformation.OBJECT.equals(type) || type.isCollectionLike())) {
179179
return value;
180180
}
181181

0 commit comments

Comments
 (0)