|
30 | 30 |
|
31 | 31 | import org.springframework.core.convert.converter.Converter;
|
32 | 32 | 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.function.convert.R2dbcConverters.RowToNumberConverterFactory.LocalDateConverterOverride; |
| 37 | +import org.springframework.data.r2dbc.function.convert.R2dbcConverters.RowToNumberConverterFactory.LocalDateTimeConverterOverride; |
| 38 | +import org.springframework.data.r2dbc.function.convert.R2dbcConverters.RowToNumberConverterFactory.LocalTimeConverterOverride; |
33 | 39 | import org.springframework.data.r2dbc.function.convert.R2dbcConverters.RowToNumberConverterFactory.RowToOffsetDateTimeConverter;
|
34 | 40 | import org.springframework.data.r2dbc.function.convert.R2dbcConverters.RowToNumberConverterFactory.RowToStringConverter;
|
35 | 41 | import org.springframework.data.r2dbc.function.convert.R2dbcConverters.RowToNumberConverterFactory.RowToUuidConverter;
|
@@ -67,6 +73,22 @@ public static Collection<Object> getConvertersToRegister() {
|
67 | 73 | return converters;
|
68 | 74 | }
|
69 | 75 |
|
| 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 | + |
70 | 92 | /**
|
71 | 93 | * Simple singleton to convert {@link Row}s to their {@link Boolean} representation.
|
72 | 94 | *
|
@@ -229,5 +251,53 @@ public ZonedDateTime convert(Row row) {
|
229 | 251 | return row.get(0, ZonedDateTime.class);
|
230 | 252 | }
|
231 | 253 | }
|
| 254 | + |
| 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 | + } |
232 | 302 | }
|
233 | 303 | }
|
0 commit comments