Browse Source

Drop defensive Joda-Time 2.x check

pull/1172/head
Juergen Hoeller 9 years ago
parent
commit
118d093eaf
  1. 26
      spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormatterRegistrar.java

26
spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormatterRegistrar.java

@ -38,7 +38,6 @@ import org.springframework.format.FormatterRegistry; @@ -38,7 +38,6 @@ import org.springframework.format.FormatterRegistry;
import org.springframework.format.Parser;
import org.springframework.format.Printer;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.util.ClassUtils;
/**
* Configures Joda-Time's formatting system for use with Spring.
@ -62,14 +61,6 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar { @@ -62,14 +61,6 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
private enum Type {DATE, TIME, DATE_TIME}
/**
* Strictly speaking, this should not be necessary since we formally require JodaTime 2.x.
* However, since Joda-Time formatters are being registered automatically, we defensively
* adapt to Joda-Time 1.x when encountered on the classpath. To be removed in Spring 5.0.
*/
private static final boolean jodaTime2Available = ClassUtils.isPresent(
"org.joda.time.YearMonth", JodaTimeFormatterRegistrar.class.getClassLoader());
/**
* User defined formatters.
*/
@ -209,9 +200,8 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar { @@ -209,9 +200,8 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
if (jodaTime2Available) {
JodaTime2Delegate.registerAdditionalFormatters(registry);
}
registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
@ -241,16 +231,4 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar { @@ -241,16 +231,4 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
}
}
/**
* Inner class to avoid a hard dependency on Joda-Time 2.x.
*/
private static class JodaTime2Delegate {
public static void registerAdditionalFormatters(FormatterRegistry registry) {
registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
}
}

Loading…
Cancel
Save