Remove …ConverterOverride converters in favor of R2dbcCustomConversionsConfiguration converter filters.
Closes #1225
This commit is contained in:
@@ -30,12 +30,6 @@ import java.util.UUID;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
import org.springframework.data.convert.CustomConversions;
|
||||
import org.springframework.data.convert.Jsr310Converters;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.LocalDateConverterOverride;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.LocalDateTimeConverterOverride;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.LocalTimeConverterOverride;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.RowToOffsetDateTimeConverter;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.RowToStringConverter;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.RowToUuidConverter;
|
||||
@@ -73,22 +67,6 @@ abstract class R2dbcConverters {
|
||||
return converters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of the registered converters to enforce JSR-310 type usage.
|
||||
* @see CustomConversions#DEFAULT_CONVERTERS
|
||||
* @see Jsr310Converters
|
||||
*/
|
||||
public static Collection<Object> getOverrideConvertersToRegister() {
|
||||
|
||||
List<Object> converters = new ArrayList<>();
|
||||
|
||||
converters.add(LocalDateConverterOverride.INSTANCE);
|
||||
converters.add(LocalDateTimeConverterOverride.INSTANCE);
|
||||
converters.add(LocalTimeConverterOverride.INSTANCE);
|
||||
|
||||
return converters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple singleton to convert {@link Row}s to their {@link Boolean} representation.
|
||||
*
|
||||
@@ -252,52 +230,5 @@ abstract class R2dbcConverters {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Converter} override that forces {@link LocalDate} to stay on {@link LocalDate}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@WritingConverter
|
||||
public enum LocalDateConverterOverride implements Converter<LocalDate, LocalDate> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public LocalDate convert(LocalDate value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Converter} override that forces {@link LocalDateTime} to stay on {@link LocalDateTime}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@WritingConverter
|
||||
public enum LocalDateTimeConverterOverride implements Converter<LocalDateTime, LocalDateTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public LocalDateTime convert(LocalDateTime value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Converter} override that forces {@link LocalTime} to stay on {@link LocalTime}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@WritingConverter
|
||||
public enum LocalTimeConverterOverride implements Converter<LocalTime, LocalTime> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public LocalTime convert(LocalTime value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ public class R2dbcCustomConversions extends CustomConversions {
|
||||
*/
|
||||
@Deprecated
|
||||
public R2dbcCustomConversions(Collection<?> converters) {
|
||||
super(new R2dbcCustomConversionsConfiguration(STORE_CONVERSIONS, appendOverrides(converters)));
|
||||
super(new R2dbcCustomConversionsConfiguration(STORE_CONVERSIONS,
|
||||
converters instanceof List ? (List<?>) converters : new ArrayList<>(converters)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,12 @@ public class R2dbcCustomConversions extends CustomConversions {
|
||||
* @param converters must not be {@literal null}.
|
||||
*/
|
||||
public R2dbcCustomConversions(StoreConversions storeConversions, Collection<?> converters) {
|
||||
super(new R2dbcCustomConversionsConfiguration(storeConversions, appendOverrides(converters)));
|
||||
super(new R2dbcCustomConversionsConfiguration(storeConversions,
|
||||
converters instanceof List ? (List<?>) converters : new ArrayList<>(converters)));
|
||||
}
|
||||
|
||||
protected R2dbcCustomConversions(ConverterConfiguration converterConfiguration) {
|
||||
super(converterConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,19 +90,12 @@ public class R2dbcCustomConversions extends CustomConversions {
|
||||
return new R2dbcCustomConversions(StoreConversions.of(dialect.getSimpleTypeHolder(), storeConverters), converters);
|
||||
}
|
||||
|
||||
private static List<?> appendOverrides(Collection<?> converters) {
|
||||
|
||||
List<Object> objects = new ArrayList<>(converters);
|
||||
objects.addAll(R2dbcConverters.getOverrideConvertersToRegister());
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
static class R2dbcCustomConversionsConfiguration extends ConverterConfiguration {
|
||||
|
||||
public R2dbcCustomConversionsConfiguration(StoreConversions storeConversions, List<?> userConverters) {
|
||||
super(storeConversions, userConverters, convertiblePair -> {
|
||||
|
||||
// Avoid JSR-310 temporal types conversion into java.util.Date
|
||||
if (convertiblePair.getSourceType().getName().startsWith("java.time.")
|
||||
&& convertiblePair.getTargetType().equals(Date.class)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user