Correctly convert enum array values.

We now correctly convert array write values. Previously, enum arrays were converted to null as these fell through the entity conversion.

Closes #1593
This commit is contained in:
Mark Paluch
2023-08-23 15:39:38 +02:00
parent e1ecb4b50b
commit b522ad5eea
3 changed files with 108 additions and 37 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.r2dbc.core;
import static org.mockito.Mockito.*;
import static org.springframework.data.r2dbc.testing.Assertions.*;
import io.r2dbc.postgresql.codec.Interval;
@@ -33,9 +34,13 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.data.r2dbc.convert.EnumWriteSupport;
import org.springframework.data.r2dbc.core.StatementMapper.InsertSpec;
import org.springframework.data.r2dbc.dialect.PostgresDialect;
import org.springframework.data.r2dbc.mapping.OutboundRow;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.r2dbc.core.Parameter;
import org.springframework.r2dbc.core.PreparedOperation;
import org.springframework.r2dbc.core.binding.BindTarget;
/**
* {@link PostgresDialect} specific tests for {@link ReactiveDataAccessStrategy}.
@@ -60,6 +65,20 @@ public class PostgresReactiveDataAccessStrategyTests extends ReactiveDataAccessS
assertThat(row).withColumn("myarray").hasValueInstanceOf(Integer[][].class);
}
@Test // GH-1593
void shouldConvertEnumsCorrectly() {
StatementMapper mapper = strategy.getStatementMapper();
MyEnum[] value = { MyEnum.ONE };
InsertSpec insert = mapper.createInsert("table").withColumn("my_col", Parameter.from(value));
PreparedOperation<?> mappedObject = mapper.getMappedObject(insert);
BindTarget bindTarget = mock(BindTarget.class);
mappedObject.bindTo(bindTarget);
verify(bindTarget).bind(0, new String[] { "ONE" });
}
@Test // gh-161
void shouldConvertNullArrayToDriverArrayType() {