Deprecate R2dbcCustomConversions constructor taking Collection of converters.

Creating R2dbcCustomConversions without a dialect or StoreConversions can easily lead to misconfiguration that isn't immediately obvious because of missing store simple types. We now deprecated the constructor and have added guidance on how to properly create R2dbcCustomConversions that is associated with a dialect.

Closes #628
This commit is contained in:
Mark Paluch
2021-07-21 09:18:56 +02:00
parent cafab47116
commit d622065ee6
4 changed files with 8 additions and 3 deletions

View File

@@ -70,7 +70,7 @@ public class MappingR2dbcConverter extends BasicRelationalConverter implements R
*/
public MappingR2dbcConverter(
MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context) {
super(context, new R2dbcCustomConversions(Collections.emptyList()));
super(context, new R2dbcCustomConversions(CustomConversions.StoreConversions.NONE, Collections.emptyList()));
}
/**

View File

@@ -41,7 +41,11 @@ public class R2dbcCustomConversions extends CustomConversions {
* Create a new {@link R2dbcCustomConversions} instance registering the given converters.
*
* @param converters must not be {@literal null}.
* @deprecated since 1.3, use {@link #of(R2dbcDialect, Object...)} or
* {@link #R2dbcCustomConversions(StoreConversions, Collection)} directly to consider dialect-native
* simple types. Use {@link CustomConversions.StoreConversions#NONE} to omit store-specific converters.
*/
@Deprecated
public R2dbcCustomConversions(Collection<?> converters) {
super(new R2dbcCustomConversionsConfiguration(STORE_CONVERSIONS, appendOverrides(converters)));
}

View File

@@ -41,6 +41,7 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.data.r2dbc.mapping.OutboundRow;
@@ -62,7 +63,7 @@ public class MappingR2dbcConverterUnitTests {
@BeforeEach
void before() {
R2dbcCustomConversions conversions = new R2dbcCustomConversions(
R2dbcCustomConversions conversions = new R2dbcCustomConversions(CustomConversions.StoreConversions.NONE,
Arrays.asList(StringToMapConverter.INSTANCE, MapToStringConverter.INSTANCE,
CustomConversionPersonToOutboundRowConverter.INSTANCE, RowToCustomConversionPerson.INSTANCE));

View File

@@ -45,7 +45,7 @@ public class R2dbcMappingContextUnitTests {
@Test
public void shouldCreateMetadataForConvertedTypes() {
R2dbcCustomConversions conversions = new R2dbcCustomConversions(
R2dbcCustomConversions conversions = new R2dbcCustomConversions(CustomConversions.StoreConversions.NONE,
Arrays.asList(ConvertedEntityToRow.INSTANCE, RowToConvertedEntity.INSTANCE));
R2dbcMappingContext context = new R2dbcMappingContext();
context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());