diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java index 55f7665b1261..97ea4e59625e 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java @@ -27,7 +27,6 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterRegistry; -import org.springframework.format.datetime.DateFormatterRegistrar; /** * Installs lower-level type converters required to integrate @@ -52,8 +51,6 @@ private DateTimeConverters() { * @param registry the converter registry */ public static void registerConverters(ConverterRegistry registry) { - DateFormatterRegistrar.addDateConverters(registry); - registry.addConverter(new LocalDateTimeToLocalDateConverter()); registry.addConverter(new LocalDateTimeToLocalTimeConverter()); registry.addConverter(new ZonedDateTimeToLocalDateConverter()); diff --git a/spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceTests.java b/spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceTests.java index 3f2468baade3..eab15a3c286f 100644 --- a/spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceTests.java +++ b/spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceTests.java @@ -176,6 +176,24 @@ void proxiedConverterFactory() { assertThat(formattingService.convert("1", Integer.class)).isEqualTo(Integer.valueOf(1)); } + @Test + void defaultFormattingConversionServiceHasNoDuplicateDateConverters() { + DefaultFormattingConversionService service = new DefaultFormattingConversionService(); + String serviceString = service.toString(); + int count = countOccurrences(serviceString, "DateFormatterRegistrar$DateToLongConverter"); + assertThat(count).isEqualTo(1); + } + + private int countOccurrences(String str, String subStr) { + int count = 0; + int idx = 0; + while ((idx = str.indexOf(subStr, idx)) != -1) { + count++; + idx += subStr.length(); + } + return count; + } + static class NullReturningFormatter implements Formatter {