Skip to content

Commit 1ae5174

Browse files
committed
Remove …ConverterOverride converters in favor of R2dbcCustomConversionsConfiguration converter filters.
Closes #1225
1 parent e874f01 commit 1ae5174

File tree

2 files changed

+9
-79
lines changed

2 files changed

+9
-79
lines changed

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/R2dbcConverters.java

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030

3131
import org.springframework.core.convert.converter.Converter;
3232
import org.springframework.core.convert.converter.ConverterFactory;
33-
import org.springframework.data.convert.CustomConversions;
34-
import org.springframework.data.convert.Jsr310Converters;
35-
import org.springframework.data.convert.WritingConverter;
36-
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.LocalDateConverterOverride;
37-
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.LocalDateTimeConverterOverride;
38-
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.LocalTimeConverterOverride;
3933
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.RowToOffsetDateTimeConverter;
4034
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.RowToStringConverter;
4135
import org.springframework.data.r2dbc.convert.R2dbcConverters.RowToNumberConverterFactory.RowToUuidConverter;
@@ -73,22 +67,6 @@ public static Collection<Object> getConvertersToRegister() {
7367
return converters;
7468
}
7569

76-
/**
77-
* @return A list of the registered converters to enforce JSR-310 type usage.
78-
* @see CustomConversions#DEFAULT_CONVERTERS
79-
* @see Jsr310Converters
80-
*/
81-
public static Collection<Object> getOverrideConvertersToRegister() {
82-
83-
List<Object> converters = new ArrayList<>();
84-
85-
converters.add(LocalDateConverterOverride.INSTANCE);
86-
converters.add(LocalDateTimeConverterOverride.INSTANCE);
87-
converters.add(LocalTimeConverterOverride.INSTANCE);
88-
89-
return converters;
90-
}
91-
9270
/**
9371
* Simple singleton to convert {@link Row}s to their {@link Boolean} representation.
9472
*
@@ -252,52 +230,5 @@ public ZonedDateTime convert(Row row) {
252230
}
253231
}
254232

255-
/**
256-
* {@link Converter} override that forces {@link LocalDate} to stay on {@link LocalDate}.
257-
*
258-
* @author Mark Paluch
259-
*/
260-
@WritingConverter
261-
public enum LocalDateConverterOverride implements Converter<LocalDate, LocalDate> {
262-
263-
INSTANCE;
264-
265-
@Override
266-
public LocalDate convert(LocalDate value) {
267-
return value;
268-
}
269-
}
270-
271-
/**
272-
* {@link Converter} override that forces {@link LocalDateTime} to stay on {@link LocalDateTime}.
273-
*
274-
* @author Mark Paluch
275-
*/
276-
@WritingConverter
277-
public enum LocalDateTimeConverterOverride implements Converter<LocalDateTime, LocalDateTime> {
278-
279-
INSTANCE;
280-
281-
@Override
282-
public LocalDateTime convert(LocalDateTime value) {
283-
return value;
284-
}
285-
}
286-
287-
/**
288-
* {@link Converter} override that forces {@link LocalTime} to stay on {@link LocalTime}.
289-
*
290-
* @author Mark Paluch
291-
*/
292-
@WritingConverter
293-
public enum LocalTimeConverterOverride implements Converter<LocalTime, LocalTime> {
294-
295-
INSTANCE;
296-
297-
@Override
298-
public LocalTime convert(LocalTime value) {
299-
return value;
300-
}
301-
}
302233
}
303234
}

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/R2dbcCustomConversions.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class R2dbcCustomConversions extends CustomConversions {
4343
*/
4444
@Deprecated
4545
public R2dbcCustomConversions(Collection<?> converters) {
46-
super(new R2dbcCustomConversionsConfiguration(STORE_CONVERSIONS, appendOverrides(converters)));
46+
super(new R2dbcCustomConversionsConfiguration(STORE_CONVERSIONS,
47+
converters instanceof List ? (List<?>) converters : new ArrayList<>(converters)));
4748
}
4849

4950
/**
@@ -53,7 +54,12 @@ public R2dbcCustomConversions(Collection<?> converters) {
5354
* @param converters must not be {@literal null}.
5455
*/
5556
public R2dbcCustomConversions(StoreConversions storeConversions, Collection<?> converters) {
56-
super(new R2dbcCustomConversionsConfiguration(storeConversions, appendOverrides(converters)));
57+
super(new R2dbcCustomConversionsConfiguration(storeConversions,
58+
converters instanceof List ? (List<?>) converters : new ArrayList<>(converters)));
59+
}
60+
61+
protected R2dbcCustomConversions(ConverterConfiguration converterConfiguration) {
62+
super(converterConfiguration);
5763
}
5864

5965
/**
@@ -84,19 +90,12 @@ public static R2dbcCustomConversions of(R2dbcDialect dialect, Collection<?> conv
8490
return new R2dbcCustomConversions(StoreConversions.of(dialect.getSimpleTypeHolder(), storeConverters), converters);
8591
}
8692

87-
private static List<?> appendOverrides(Collection<?> converters) {
88-
89-
List<Object> objects = new ArrayList<>(converters);
90-
objects.addAll(R2dbcConverters.getOverrideConvertersToRegister());
91-
92-
return objects;
93-
}
94-
9593
static class R2dbcCustomConversionsConfiguration extends ConverterConfiguration {
9694

9795
public R2dbcCustomConversionsConfiguration(StoreConversions storeConversions, List<?> userConverters) {
9896
super(storeConversions, userConverters, convertiblePair -> {
9997

98+
// Avoid JSR-310 temporal types conversion into java.util.Date
10099
if (convertiblePair.getSourceType().getName().startsWith("java.time.")
101100
&& convertiblePair.getTargetType().equals(Date.class)) {
102101
return false;

0 commit comments

Comments
 (0)