Remove Joda-Time support

Closes gh-27426
This commit is contained in:
Juergen Hoeller
2021-09-17 08:58:40 +02:00
parent b74e93807e
commit b7b078d26e
34 changed files with 126 additions and 3003 deletions

View File

@@ -66,7 +66,6 @@ import java.lang.annotation.Target;
* @author Sam Brannen
* @since 3.0
* @see java.time.format.DateTimeFormatter
* @see org.joda.time.format.DateTimeFormat
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,6 @@ import org.springframework.util.Assert;
* @author Phillip Webb
* @since 3.2
* @see org.springframework.format.datetime.standard.DateTimeFormatterRegistrar
* @see org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar
* @see FormatterRegistrar#registerFormatters
*/
public class DateFormatterRegistrar implements FormatterRegistrar {

View File

@@ -38,7 +38,6 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb
* @author Sam Brannen
* @since 3.2
* @see org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory
*/
public class DateTimeFormatAnnotationFormatterFactory extends EmbeddedValueResolutionSupport
implements AnnotationFormatterFactory<DateTimeFormat> {

View File

@@ -1,169 +0,0 @@
/*
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.TimeZone;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
* Factory that creates a Joda-Time {@link DateTimeFormatter}.
*
* <p>Formatters will be created using the defined {@link #setPattern pattern},
* {@link #setIso ISO}, and {@link #setStyle style} methods (considered in that order).
*
* @author Phillip Webb
* @author Sam Brannen
* @since 3.2
* @see #createDateTimeFormatter()
* @see #createDateTimeFormatter(DateTimeFormatter)
* @see #setPattern
* @see #setStyle
* @see #setIso
* @see DateTimeFormatterFactoryBean
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public class DateTimeFormatterFactory {
@Nullable
private String pattern;
@Nullable
private ISO iso;
@Nullable
private String style;
@Nullable
private TimeZone timeZone;
/**
* Create a new {@code DateTimeFormatterFactory} instance.
*/
public DateTimeFormatterFactory() {
}
/**
* Create a new {@code DateTimeFormatterFactory} instance.
* @param pattern the pattern to use to format date values
*/
public DateTimeFormatterFactory(String pattern) {
this.pattern = pattern;
}
/**
* Set the pattern to use to format date values.
* @param pattern the format pattern
*/
public void setPattern(String pattern) {
this.pattern = pattern;
}
/**
* Set the ISO format used to format date values.
* @param iso the ISO format
*/
public void setIso(ISO iso) {
this.iso = iso;
}
/**
* Set the two characters to use to format date values, in Joda-Time style.
* <p>The first character is used for the date style; the second is for
* the time style. Supported characters are:
* <ul>
* <li>'S' = Small</li>
* <li>'M' = Medium</li>
* <li>'L' = Long</li>
* <li>'F' = Full</li>
* <li>'-' = Omitted</li>
* </ul>
* @param style two characters from the set {"S", "M", "L", "F", "-"}
*/
public void setStyle(String style) {
this.style = style;
}
/**
* Set the {@code TimeZone} to normalize the date values into, if any.
* @param timeZone the time zone
*/
public void setTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
}
/**
* Create a new {@code DateTimeFormatter} using this factory.
* <p>If no specific pattern or style has been defined,
* {@link DateTimeFormat#mediumDateTime() medium date time format} will be used.
* @return a new date time formatter
* @see #createDateTimeFormatter(DateTimeFormatter)
*/
public DateTimeFormatter createDateTimeFormatter() {
return createDateTimeFormatter(DateTimeFormat.mediumDateTime());
}
/**
* Create a new {@code DateTimeFormatter} using this factory.
* <p>If no specific pattern or style has been defined,
* the supplied {@code fallbackFormatter} will be used.
* @param fallbackFormatter the fall-back formatter to use
* when no specific factory properties have been set
* @return a new date time formatter
*/
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
DateTimeFormatter dateTimeFormatter = null;
if (StringUtils.hasLength(this.pattern)) {
dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
}
else if (this.iso != null && this.iso != ISO.NONE) {
switch (this.iso) {
case DATE:
dateTimeFormatter = ISODateTimeFormat.date();
break;
case TIME:
dateTimeFormatter = ISODateTimeFormat.time();
break;
case DATE_TIME:
dateTimeFormatter = ISODateTimeFormat.dateTime();
break;
default:
throw new IllegalStateException("Unsupported ISO format: " + this.iso);
}
}
else if (StringUtils.hasLength(this.style)) {
dateTimeFormatter = DateTimeFormat.forStyle(this.style);
}
if (dateTimeFormatter != null && this.timeZone != null) {
dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
}
return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
/**
* {@link FactoryBean} that creates a Joda-Time {@link DateTimeFormatter}.
* See the {@link DateTimeFormatterFactory base class} for configuration details.
*
* @author Phillip Webb
* @author Sam Brannen
* @since 3.2
* @see #setPattern
* @see #setIso
* @see #setStyle
* @see DateTimeFormatterFactory
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory
implements FactoryBean<DateTimeFormatter>, InitializingBean {
@Nullable
private DateTimeFormatter dateTimeFormatter;
@Override
public void afterPropertiesSet() {
this.dateTimeFormatter = createDateTimeFormatter();
}
@Override
@Nullable
public DateTimeFormatter getObject() {
return this.dateTimeFormatter;
}
@Override
public Class<?> getObjectType() {
return DateTimeFormatter.class;
}
@Override
public boolean isSingleton() {
return true;
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Parser;
/**
* Parses Joda {@link DateTime} instances using a {@link DateTimeFormatter}.
*
* @author Keith Donald
* @since 3.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class DateTimeParser implements Parser<DateTime> {
private final DateTimeFormatter formatter;
/**
* Create a new DateTimeParser.
* @param formatter the Joda DateTimeFormatter instance
*/
public DateTimeParser(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public DateTime parse(String text, Locale locale) throws ParseException {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseDateTime(text);
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.Duration;
import org.springframework.format.Formatter;
/**
* {@link Formatter} implementation for a Joda-Time {@link Duration},
* following Joda-Time's parsing rules for a Duration.
*
* @author Juergen Hoeller
* @since 4.2.4
* @see Duration#parse
*/
class DurationFormatter implements Formatter<Duration> {
@Override
public Duration parse(String text, Locale locale) throws ParseException {
return Duration.parse(text);
}
@Override
public String print(Duration object, Locale locale) {
return object.toString();
}
}

View File

@@ -1,133 +0,0 @@
/*
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.joda.time.ReadableInstant;
import org.joda.time.ReadablePartial;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.context.support.EmbeddedValueResolutionSupport;
import org.springframework.format.AnnotationFormatterFactory;
import org.springframework.format.Parser;
import org.springframework.format.Printer;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation using Joda-Time.
*
* <p><b>NOTE:</b> Spring's Joda-Time support requires Joda-Time 2.x, as of Spring 4.0.
*
* @author Keith Donald
* @author Juergen Hoeller
* @since 3.0
* @see DateTimeFormat
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public class JodaDateTimeFormatAnnotationFormatterFactory extends EmbeddedValueResolutionSupport
implements AnnotationFormatterFactory<DateTimeFormat> {
private static final Set<Class<?>> FIELD_TYPES;
static {
// Create the set of field types that may be annotated with @DateTimeFormat.
// Note: the 3 ReadablePartial concrete types are registered explicitly since
// addFormatterForFieldType rules exist for each of these types
// (if we did not do this, the default byType rules for LocalDate, LocalTime,
// and LocalDateTime would take precedence over the annotation rule, which
// is not what we want)
Set<Class<?>> fieldTypes = new HashSet<>(8);
fieldTypes.add(ReadableInstant.class);
fieldTypes.add(LocalDate.class);
fieldTypes.add(LocalTime.class);
fieldTypes.add(LocalDateTime.class);
fieldTypes.add(Date.class);
fieldTypes.add(Calendar.class);
fieldTypes.add(Long.class);
FIELD_TYPES = Collections.unmodifiableSet(fieldTypes);
}
@Override
public final Set<Class<?>> getFieldTypes() {
return FIELD_TYPES;
}
@Override
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
DateTimeFormatter formatter = getFormatter(annotation, fieldType);
if (ReadablePartial.class.isAssignableFrom(fieldType)) {
return new ReadablePartialPrinter(formatter);
}
else if (ReadableInstant.class.isAssignableFrom(fieldType) || Calendar.class.isAssignableFrom(fieldType)) {
// assumes Calendar->ReadableInstant converter is registered
return new ReadableInstantPrinter(formatter);
}
else {
// assumes Date->Long converter is registered
return new MillisecondInstantPrinter(formatter);
}
}
@Override
public Parser<?> getParser(DateTimeFormat annotation, Class<?> fieldType) {
if (LocalDate.class == fieldType) {
return new LocalDateParser(getFormatter(annotation, fieldType));
}
else if (LocalTime.class == fieldType) {
return new LocalTimeParser(getFormatter(annotation, fieldType));
}
else if (LocalDateTime.class == fieldType) {
return new LocalDateTimeParser(getFormatter(annotation, fieldType));
}
else {
return new DateTimeParser(getFormatter(annotation, fieldType));
}
}
/**
* Factory method used to create a {@link DateTimeFormatter}.
* @param annotation the format annotation for the field
* @param fieldType the type of field
* @return a {@link DateTimeFormatter} instance
* @since 3.2
*/
protected DateTimeFormatter getFormatter(DateTimeFormat annotation, Class<?> fieldType) {
DateTimeFormatterFactory factory = new DateTimeFormatterFactory();
String style = resolveEmbeddedValue(annotation.style());
if (StringUtils.hasLength(style)) {
factory.setStyle(style);
}
factory.setIso(annotation.iso());
String pattern = resolveEmbeddedValue(annotation.pattern());
if (StringUtils.hasLength(pattern)) {
factory.setPattern(pattern);
}
return factory.createDateTimeFormatter();
}
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.TimeZone;
import org.joda.time.Chronology;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
import org.springframework.lang.Nullable;
/**
* A context that holds user-specific Joda-Time settings such as the user's
* Chronology (calendar system) and time zone.
*
* <p>A {@code null} property value indicate the user has not specified a setting.
*
* @author Keith Donald
* @since 3.0
* @see JodaTimeContextHolder
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public class JodaTimeContext {
@Nullable
private Chronology chronology;
@Nullable
private DateTimeZone timeZone;
/**
* Set the user's chronology (calendar system).
*/
public void setChronology(@Nullable Chronology chronology) {
this.chronology = chronology;
}
/**
* Return the user's chronology (calendar system), if any.
*/
@Nullable
public Chronology getChronology() {
return this.chronology;
}
/**
* Set the user's time zone.
* <p>Alternatively, set a {@link TimeZoneAwareLocaleContext} on
* {@link LocaleContextHolder}. This context class will fall back to
* checking the locale context if no setting has been provided here.
* @see org.springframework.context.i18n.LocaleContextHolder#getTimeZone()
* @see org.springframework.context.i18n.LocaleContextHolder#setLocaleContext
*/
public void setTimeZone(@Nullable DateTimeZone timeZone) {
this.timeZone = timeZone;
}
/**
* Return the user's time zone, if any.
*/
@Nullable
public DateTimeZone getTimeZone() {
return this.timeZone;
}
/**
* Get the DateTimeFormatter with the this context's settings
* applied to the base {@code formatter}.
* @param formatter the base formatter that establishes default
* formatting rules, generally context-independent
* @return the contextual DateTimeFormatter
*/
public DateTimeFormatter getFormatter(DateTimeFormatter formatter) {
if (this.chronology != null) {
formatter = formatter.withChronology(this.chronology);
}
if (this.timeZone != null) {
formatter = formatter.withZone(this.timeZone);
}
else {
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
if (localeContext instanceof TimeZoneAwareLocaleContext) {
TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
if (timeZone != null) {
formatter = formatter.withZone(DateTimeZone.forTimeZone(timeZone));
}
}
}
return formatter;
}
}

View File

@@ -1,91 +0,0 @@
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Locale;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
/**
* A holder for a thread-local {@link JodaTimeContext}
* with user-specific Joda-Time settings.
*
* @author Keith Donald
* @author Juergen Hoeller
* @since 3.0
* @see org.springframework.context.i18n.LocaleContextHolder
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class JodaTimeContextHolder {
private static final ThreadLocal<JodaTimeContext> jodaTimeContextHolder =
new NamedThreadLocal<>("JodaTimeContext");
private JodaTimeContextHolder() {
}
/**
* Reset the JodaTimeContext for the current thread.
*/
public static void resetJodaTimeContext() {
jodaTimeContextHolder.remove();
}
/**
* Associate the given JodaTimeContext with the current thread.
* @param jodaTimeContext the current JodaTimeContext,
* or {@code null} to reset the thread-bound context
*/
public static void setJodaTimeContext(@Nullable JodaTimeContext jodaTimeContext) {
if (jodaTimeContext == null) {
resetJodaTimeContext();
}
else {
jodaTimeContextHolder.set(jodaTimeContext);
}
}
/**
* Return the JodaTimeContext associated with the current thread, if any.
* @return the current JodaTimeContext, or {@code null} if none
*/
@Nullable
public static JodaTimeContext getJodaTimeContext() {
return jodaTimeContextHolder.get();
}
/**
* Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
* @param formatter the base formatter that establishes default formatting rules
* (generally user independent)
* @param locale the current user locale (may be {@code null} if not known)
* @return the user-specific DateTimeFormatter
*/
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) {
DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
JodaTimeContext context = getJodaTimeContext();
return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
}
}

View File

@@ -1,219 +0,0 @@
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Calendar;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.Instant;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.joda.time.MutableDateTime;
import org.joda.time.ReadableInstant;
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
* Joda-Time support into Spring's field formatting system.
*
* <p>Note: {@link JodaTimeFormatterRegistrar} installs these converters
* and relies on several of them for its formatters. Some additional
* converters are just being registered for custom conversion scenarios.
*
* @author Keith Donald
* @author Phillip Webb
* @author Juergen Hoeller
* @since 3.0
*/
final class JodaTimeConverters {
private JodaTimeConverters() {
}
/**
* Install the converters into the converter registry.
* @param registry the converter registry
*/
@SuppressWarnings("deprecation")
public static void registerConverters(ConverterRegistry registry) {
DateFormatterRegistrar.addDateConverters(registry);
registry.addConverter(new DateTimeToLocalDateConverter());
registry.addConverter(new DateTimeToLocalTimeConverter());
registry.addConverter(new DateTimeToLocalDateTimeConverter());
registry.addConverter(new DateTimeToDateMidnightConverter());
registry.addConverter(new DateTimeToMutableDateTimeConverter());
registry.addConverter(new DateTimeToInstantConverter());
registry.addConverter(new DateTimeToDateConverter());
registry.addConverter(new DateTimeToCalendarConverter());
registry.addConverter(new DateTimeToLongConverter());
registry.addConverter(new DateToReadableInstantConverter());
registry.addConverter(new CalendarToReadableInstantConverter());
registry.addConverter(new LongToReadableInstantConverter());
registry.addConverter(new LocalDateTimeToLocalDateConverter());
registry.addConverter(new LocalDateTimeToLocalTimeConverter());
}
private static class DateTimeToLocalDateConverter implements Converter<DateTime, LocalDate> {
@Override
public LocalDate convert(DateTime source) {
return source.toLocalDate();
}
}
private static class DateTimeToLocalTimeConverter implements Converter<DateTime, LocalTime> {
@Override
public LocalTime convert(DateTime source) {
return source.toLocalTime();
}
}
private static class DateTimeToLocalDateTimeConverter implements Converter<DateTime, LocalDateTime> {
@Override
public LocalDateTime convert(DateTime source) {
return source.toLocalDateTime();
}
}
@Deprecated
private static class DateTimeToDateMidnightConverter implements Converter<DateTime, org.joda.time.DateMidnight> {
@Override
public org.joda.time.DateMidnight convert(DateTime source) {
return source.toDateMidnight();
}
}
private static class DateTimeToMutableDateTimeConverter implements Converter<DateTime, MutableDateTime> {
@Override
public MutableDateTime convert(DateTime source) {
return source.toMutableDateTime();
}
}
private static class DateTimeToInstantConverter implements Converter<DateTime, Instant> {
@Override
public Instant convert(DateTime source) {
return source.toInstant();
}
}
private static class DateTimeToDateConverter implements Converter<DateTime, Date> {
@Override
public Date convert(DateTime source) {
return source.toDate();
}
}
private static class DateTimeToCalendarConverter implements Converter<DateTime, Calendar> {
@Override
public Calendar convert(DateTime source) {
return source.toGregorianCalendar();
}
}
private static class DateTimeToLongConverter implements Converter<DateTime, Long> {
@Override
public Long convert(DateTime source) {
return source.getMillis();
}
}
/**
* Used when printing a {@code java.util.Date} field with a ReadableInstantPrinter.
* @see MillisecondInstantPrinter
* @see JodaDateTimeFormatAnnotationFormatterFactory
*/
private static class DateToReadableInstantConverter implements Converter<Date, ReadableInstant> {
@Override
public ReadableInstant convert(Date source) {
return new DateTime(source);
}
}
/**
* Used when printing a {@code java.util.Calendar} field with a ReadableInstantPrinter.
* @see MillisecondInstantPrinter
* @see JodaDateTimeFormatAnnotationFormatterFactory
*/
private static class CalendarToReadableInstantConverter implements Converter<Calendar, ReadableInstant> {
@Override
public ReadableInstant convert(Calendar source) {
return new DateTime(source);
}
}
/**
* Used when printing a Long field with a ReadableInstantPrinter.
* @see MillisecondInstantPrinter
* @see JodaDateTimeFormatAnnotationFormatterFactory
*/
private static class LongToReadableInstantConverter implements Converter<Long, ReadableInstant> {
@Override
public ReadableInstant convert(Long source) {
return new DateTime(source.longValue());
}
}
private static class LocalDateTimeToLocalDateConverter implements Converter<LocalDateTime, LocalDate> {
@Override
public LocalDate convert(LocalDateTime source) {
return source.toLocalDate();
}
}
private static class LocalDateTimeToLocalTimeConverter implements Converter<LocalDateTime, LocalTime> {
@Override
public LocalTime convert(LocalDateTime source) {
return source.toLocalTime();
}
}
}

View File

@@ -1,236 +0,0 @@
/*
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Calendar;
import java.util.Date;
import java.util.EnumMap;
import java.util.Map;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.joda.time.MonthDay;
import org.joda.time.Period;
import org.joda.time.ReadableInstant;
import org.joda.time.YearMonth;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.FormatterRegistrar;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.Parser;
import org.springframework.format.Printer;
import org.springframework.format.annotation.DateTimeFormat.ISO;
/**
* Configures Joda-Time's formatting system for use with Spring.
*
* <p><b>NOTE:</b> Spring's Joda-Time support requires Joda-Time 2.x, as of Spring 4.0.
*
* @author Keith Donald
* @author Juergen Hoeller
* @author Phillip Webb
* @since 3.1
* @see #setDateStyle
* @see #setTimeStyle
* @see #setDateTimeStyle
* @see #setUseIsoFormat
* @see FormatterRegistrar#registerFormatters
* @see org.springframework.format.datetime.DateFormatterRegistrar
* @see DateTimeFormatterFactoryBean
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
private enum Type {DATE, TIME, DATE_TIME}
/**
* User defined formatters.
*/
private final Map<Type, DateTimeFormatter> formatters = new EnumMap<>(Type.class);
/**
* Factories used when specific formatters have not been specified.
*/
private final Map<Type, DateTimeFormatterFactory> factories;
public JodaTimeFormatterRegistrar() {
this.factories = new EnumMap<>(Type.class);
for (Type type : Type.values()) {
this.factories.put(type, new DateTimeFormatterFactory());
}
}
/**
* Set whether standard ISO formatting should be applied to all date/time types.
* Default is "false" (no).
* <p>If set to "true", the "dateStyle", "timeStyle" and "dateTimeStyle"
* properties are effectively ignored.
*/
public void setUseIsoFormat(boolean useIsoFormat) {
this.factories.get(Type.DATE).setIso(useIsoFormat ? ISO.DATE : ISO.NONE);
this.factories.get(Type.TIME).setIso(useIsoFormat ? ISO.TIME : ISO.NONE);
this.factories.get(Type.DATE_TIME).setIso(useIsoFormat ? ISO.DATE_TIME : ISO.NONE);
}
/**
* Set the default format style of Joda {@link LocalDate} objects.
* Default is {@link DateTimeFormat#shortDate()}.
*/
public void setDateStyle(String dateStyle) {
this.factories.get(Type.DATE).setStyle(dateStyle + "-");
}
/**
* Set the default format style of Joda {@link LocalTime} objects.
* Default is {@link DateTimeFormat#shortTime()}.
*/
public void setTimeStyle(String timeStyle) {
this.factories.get(Type.TIME).setStyle("-" + timeStyle);
}
/**
* Set the default format style of Joda {@link LocalDateTime} and {@link DateTime} objects,
* as well as JDK {@link Date} and {@link Calendar} objects.
* Default is {@link DateTimeFormat#shortDateTime()}.
*/
public void setDateTimeStyle(String dateTimeStyle) {
this.factories.get(Type.DATE_TIME).setStyle(dateTimeStyle);
}
/**
* Set the formatter that will be used for objects representing date values.
* <p>This formatter will be used for the {@link LocalDate} type. When specified
* the {@link #setDateStyle(String) dateStyle} and
* {@link #setUseIsoFormat(boolean) useIsoFormat} properties will be ignored.
* @param formatter the formatter to use
* @since 3.2
* @see #setTimeFormatter
* @see #setDateTimeFormatter
*/
public void setDateFormatter(DateTimeFormatter formatter) {
this.formatters.put(Type.DATE, formatter);
}
/**
* Set the formatter that will be used for objects representing time values.
* <p>This formatter will be used for the {@link LocalTime} type. When specified
* the {@link #setTimeStyle(String) timeStyle} and
* {@link #setUseIsoFormat(boolean) useIsoFormat} properties will be ignored.
* @param formatter the formatter to use
* @since 3.2
* @see #setDateFormatter
* @see #setDateTimeFormatter
*/
public void setTimeFormatter(DateTimeFormatter formatter) {
this.formatters.put(Type.TIME, formatter);
}
/**
* Set the formatter that will be used for objects representing date and time values.
* <p>This formatter will be used for {@link LocalDateTime}, {@link ReadableInstant},
* {@link Date} and {@link Calendar} types. When specified
* the {@link #setDateTimeStyle(String) dateTimeStyle} and
* {@link #setUseIsoFormat(boolean) useIsoFormat} properties will be ignored.
* @param formatter the formatter to use
* @since 3.2
* @see #setDateFormatter
* @see #setTimeFormatter
*/
public void setDateTimeFormatter(DateTimeFormatter formatter) {
this.formatters.put(Type.DATE_TIME, formatter);
}
@Override
public void registerFormatters(FormatterRegistry registry) {
JodaTimeConverters.registerConverters(registry);
DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);
addFormatterForFields(registry,
new ReadablePartialPrinter(dateFormatter),
new LocalDateParser(dateFormatter),
LocalDate.class);
addFormatterForFields(registry,
new ReadablePartialPrinter(timeFormatter),
new LocalTimeParser(timeFormatter),
LocalTime.class);
addFormatterForFields(registry,
new ReadablePartialPrinter(dateTimeFormatter),
new LocalDateTimeParser(dateTimeFormatter),
LocalDateTime.class);
addFormatterForFields(registry,
new ReadableInstantPrinter(dateTimeFormatter),
new DateTimeParser(dateTimeFormatter),
ReadableInstant.class);
// In order to retain backwards compatibility we only register Date/Calendar
// types when a user defined formatter is specified (see SPR-10105)
if (this.formatters.containsKey(Type.DATE_TIME)) {
addFormatterForFields(registry,
new ReadableInstantPrinter(dateTimeFormatter),
new DateTimeParser(dateTimeFormatter),
Date.class, Calendar.class);
}
registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
private DateTimeFormatter getFormatter(Type type) {
DateTimeFormatter formatter = this.formatters.get(type);
if (formatter != null) {
return formatter;
}
DateTimeFormatter fallbackFormatter = getFallbackFormatter(type);
return this.factories.get(type).createDateTimeFormatter(fallbackFormatter);
}
private DateTimeFormatter getFallbackFormatter(Type type) {
switch (type) {
case DATE: return DateTimeFormat.shortDate();
case TIME: return DateTimeFormat.shortTime();
default: return DateTimeFormat.shortDateTime();
}
}
private void addFormatterForFields(FormatterRegistry registry, Printer<?> printer,
Parser<?> parser, Class<?>... fieldTypes) {
for (Class<?> fieldType : fieldTypes) {
registry.addFormatterForFieldType(fieldType, printer, parser);
}
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Parser;
/**
* Parses Joda {@link org.joda.time.LocalDate} instances using a
* {@link org.joda.time.format.DateTimeFormatter}.
*
* @author Juergen Hoeller
* @since 4.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class LocalDateParser implements Parser<LocalDate> {
private final DateTimeFormatter formatter;
/**
* Create a new DateTimeParser.
* @param formatter the Joda DateTimeFormatter instance
*/
public LocalDateParser(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public LocalDate parse(String text, Locale locale) throws ParseException {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalDate(text);
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Parser;
/**
* Parses Joda {@link org.joda.time.LocalDateTime} instances using a
* {@link org.joda.time.format.DateTimeFormatter}.
*
* @author Juergen Hoeller
* @since 4.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class LocalDateTimeParser implements Parser<LocalDateTime> {
private final DateTimeFormatter formatter;
/**
* Create a new DateTimeParser.
* @param formatter the Joda DateTimeFormatter instance
*/
public LocalDateTimeParser(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public LocalDateTime parse(String text, Locale locale) throws ParseException {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalDateTime(text);
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Parser;
/**
* Parses Joda {@link org.joda.time.LocalTime} instances using a
* {@link org.joda.time.format.DateTimeFormatter}.
*
* @author Juergen Hoeller
* @since 4.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class LocalTimeParser implements Parser<LocalTime> {
private final DateTimeFormatter formatter;
/**
* Create a new DateTimeParser.
* @param formatter the Joda DateTimeFormatter instance
*/
public LocalTimeParser(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public LocalTime parse(String text, Locale locale) throws ParseException {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalTime(text);
}
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Locale;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Printer;
/**
* Prints Long instances using a Joda {@link DateTimeFormatter}.
*
* @author Keith Donald
* @since 3.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class MillisecondInstantPrinter implements Printer<Long> {
private final DateTimeFormatter formatter;
/**
* Create a new ReadableInstantPrinter.
* @param formatter the Joda DateTimeFormatter instance
*/
public MillisecondInstantPrinter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public String print(Long instant, Locale locale) {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(instant);
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.MonthDay;
import org.springframework.format.Formatter;
/**
* {@link Formatter} implementation for a Joda-Time {@link MonthDay},
* following Joda-Time's parsing rules for a MonthDay.
*
* @author Juergen Hoeller
* @since 4.2.4
* @see MonthDay#parse
*/
class MonthDayFormatter implements Formatter<MonthDay> {
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
return MonthDay.parse(text);
}
@Override
public String print(MonthDay object, Locale locale) {
return object.toString();
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.Period;
import org.springframework.format.Formatter;
/**
* {@link Formatter} implementation for a Joda-Time {@link Period},
* following Joda-Time's parsing rules for a Period.
*
* @author Juergen Hoeller
* @since 4.2.4
* @see Period#parse
*/
class PeriodFormatter implements Formatter<Period> {
@Override
public Period parse(String text, Locale locale) throws ParseException {
return Period.parse(text);
}
@Override
public String print(Period object, Locale locale) {
return object.toString();
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Locale;
import org.joda.time.ReadableInstant;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Printer;
/**
* Prints Joda-Time {@link ReadableInstant} instances using a {@link DateTimeFormatter}.
*
* @author Keith Donald
* @since 3.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class ReadableInstantPrinter implements Printer<ReadableInstant> {
private final DateTimeFormatter formatter;
/**
* Create a new ReadableInstantPrinter.
* @param formatter the Joda DateTimeFormatter instance
*/
public ReadableInstantPrinter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public String print(ReadableInstant instant, Locale locale) {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(instant);
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.util.Locale;
import org.joda.time.ReadablePartial;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.Printer;
/**
* Prints Joda-Time {@link ReadablePartial} instances using a {@link DateTimeFormatter}.
*
* @author Keith Donald
* @since 3.0
* @deprecated as of 5.3, in favor of standard JSR-310 support
*/
@Deprecated
public final class ReadablePartialPrinter implements Printer<ReadablePartial> {
private final DateTimeFormatter formatter;
/**
* Create a new ReadableInstantPrinter.
* @param formatter the Joda DateTimeFormatter instance
*/
public ReadablePartialPrinter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public String print(ReadablePartial partial, Locale locale) {
return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(partial);
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format.datetime.joda;
import java.text.ParseException;
import java.util.Locale;
import org.joda.time.YearMonth;
import org.springframework.format.Formatter;
/**
* {@link Formatter} implementation for a Joda-Time {@link YearMonth},
* following Joda-Time's parsing rules for a YearMonth.
*
* @author Juergen Hoeller
* @since 4.2.4
* @see YearMonth#parse
*/
class YearMonthFormatter implements Formatter<YearMonth> {
@Override
public YearMonth parse(String text, Locale locale) throws ParseException {
return YearMonth.parse(text);
}
@Override
public String print(YearMonth object, Locale locale) {
return object.toString();
}
}

View File

@@ -1,9 +0,0 @@
/**
* Integration with Joda-Time for formatting Joda date and time types as well as standard JDK Date types.
*/
@NonNullApi
@NonNullFields
package org.springframework.format.datetime.joda;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -50,7 +50,6 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
* @see #setUseIsoFormat
* @see org.springframework.format.FormatterRegistrar#registerFormatters
* @see org.springframework.format.datetime.DateFormatterRegistrar
* @see org.springframework.format.datetime.joda.DateTimeFormatterFactoryBean
*/
public class DateTimeFormatterRegistrar implements FormatterRegistrar {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,12 +48,9 @@ public class DefaultFormattingConversionService extends FormattingConversionServ
private static final boolean jsr354Present;
private static final boolean jodaTimePresent;
static {
ClassLoader classLoader = DefaultFormattingConversionService.class.getClassLoader();
jsr354Present = ClassUtils.isPresent("javax.money.MonetaryAmount", classLoader);
jodaTimePresent = ClassUtils.isPresent("org.joda.time.YearMonth", classLoader);
}
/**
@@ -104,7 +101,6 @@ public class DefaultFormattingConversionService extends FormattingConversionServ
* depending on the presence of the corresponding API on the classpath.
* @param formatterRegistry the service to register default formatters with
*/
@SuppressWarnings("deprecation")
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
// Default handling of number values
formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
@@ -121,14 +117,8 @@ public class DefaultFormattingConversionService extends FormattingConversionServ
// just handling JSR-310 specific date and time types
new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);
if (jodaTimePresent) {
// handles Joda-specific types as well as Date, Calendar, Long
new org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
}
else {
// regular DateFormat-based Date, Calendar, Long converters
new DateFormatterRegistrar().registerFormatters(formatterRegistry);
}
// regular DateFormat-based Date, Calendar, Long converters
new DateFormatterRegistrar().registerFormatters(formatterRegistry);
}
}