Skip to content

Commit c55ba78

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 5409371 commit c55ba78

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
@@ -1082,6 +1082,16 @@ void insertOnlyPropertyDoesNotGetUpdated() {
10821082
assertThat(template.findById(entity.id, WithInsertOnly.class).insertOnly).isEqualTo("first value");
10831083
}
10841084

1085+
@Test // GH-1460
1086+
void readEnumArray() {
1087+
EnumArrayOwner entity = new EnumArrayOwner();
1088+
entity.digits = new Color[]{Color.BLUE};
1089+
1090+
assertThat(template.save(entity)).isNotNull();
1091+
1092+
assertThat(template.findById(entity.id, EnumArrayOwner.class).digits).isEqualTo(new Color[]{Color.BLUE});
1093+
}
1094+
10851095
private <T extends Number> void saveAndUpdateAggregateWithVersion(VersionedAggregate aggregate,
10861096
Function<Number, T> toConcreteNumber) {
10871097
saveAndUpdateAggregateWithVersion(aggregate, toConcreteNumber, 0);
@@ -1123,6 +1133,17 @@ private Long count(String tableName) {
11231133
return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM " + tableName, emptyMap(), Long.class);
11241134
}
11251135

1136+
enum Color {
1137+
BLUE
1138+
}
1139+
1140+
@Table("ARRAY_OWNER")
1141+
private static class EnumArrayOwner {
1142+
@Id Long id;
1143+
1144+
Color[] digits;
1145+
}
1146+
11261147
@Table("ARRAY_OWNER")
11271148
private static class ArrayOwner {
11281149
@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
@@ -176,7 +176,7 @@ public Object writeValue(@Nullable Object value, TypeInformation<?> type) {
176176

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

0 commit comments

Comments
 (0)