Polishing

Issue: SPR-11259
This commit is contained in:
Juergen Hoeller 2013-12-30 19:13:04 +01:00
parent 5e00113c65
commit f0d21510f5
5 changed files with 15 additions and 16 deletions

View File

@ -60,7 +60,7 @@ public class DateFormatterRegistrar implements FormatterRegistrar {
// In order to retain back compatibility we only register Date/Calendar // In order to retain back compatibility we only register Date/Calendar
// types when a user defined formatter is specified (see SPR-10105) // types when a user defined formatter is specified (see SPR-10105)
if(this.dateFormatter != null) { if (this.dateFormatter != null) {
registry.addFormatter(this.dateFormatter); registry.addFormatter(this.dateFormatter);
registry.addFormatterForFieldType(Calendar.class, this.dateFormatter); registry.addFormatterForFieldType(Calendar.class, this.dateFormatter);
} }
@ -113,7 +113,7 @@ public class DateFormatterRegistrar implements FormatterRegistrar {
@Override @Override
public Long convert(Calendar source) { public Long convert(Calendar source) {
return source.getTime().getTime(); return source.getTimeInMillis();
} }
} }
@ -129,11 +129,11 @@ public class DateFormatterRegistrar implements FormatterRegistrar {
private static class LongToCalendarConverter implements Converter<Long, Calendar> { private static class LongToCalendarConverter implements Converter<Long, Calendar> {
private final DateToCalendarConverter dateToCalendarConverter = new DateToCalendarConverter();
@Override @Override
public Calendar convert(Long source) { public Calendar convert(Long source) {
return this.dateToCalendarConverter.convert(new Date(source)); Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(source);
return calendar;
} }
} }

View File

@ -187,7 +187,7 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
// In order to retain backwards compatibility we only register Date/Calendar // In order to retain backwards compatibility we only register Date/Calendar
// types when a user defined formatter is specified (see SPR-10105) // types when a user defined formatter is specified (see SPR-10105)
if( this.formatters.containsKey(Type.DATE_TIME)) { if (this.formatters.containsKey(Type.DATE_TIME)) {
addFormatterForFields(registry, addFormatterForFields(registry,
new ReadableInstantPrinter(dateTimeFormatter), new ReadableInstantPrinter(dateTimeFormatter),
new DateTimeParser(dateTimeFormatter), new DateTimeParser(dateTimeFormatter),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -92,10 +92,10 @@ public class Jsr310DateTimeFormatAnnotationFormatterFactory
} }
/** /**
* Factory method used to create a {@link org.joda.time.format.DateTimeFormatter}. * Factory method used to create a {@link DateTimeFormatter}.
* @param annotation the format annotation for the field * @param annotation the format annotation for the field
* @param fieldType the type of field * @param fieldType the type of field
* @return a {@link org.joda.time.format.DateTimeFormatter} instance * @return a {@link DateTimeFormatter} instance
*/ */
protected DateTimeFormatter getFormatter(DateTimeFormat annotation, Class<?> fieldType) { protected DateTimeFormatter getFormatter(DateTimeFormat annotation, Class<?> fieldType) {
DateTimeFormatterFactory factory = new DateTimeFormatterFactory(); DateTimeFormatterFactory factory = new DateTimeFormatterFactory();

View File

@ -456,6 +456,7 @@ public class GenericConversionService implements ConfigurableConversionService {
} }
} }
/** /**
* Manages all converters registered with the service. * Manages all converters registered with the service.
*/ */
@ -614,12 +615,10 @@ public class GenericConversionService implements ConfigurableConversionService {
this.converters.addFirst(converter); this.converters.addFirst(converter);
} }
public GenericConverter getConverter(TypeDescriptor sourceType, public GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
TypeDescriptor targetType) {
for (GenericConverter converter : this.converters) { for (GenericConverter converter : this.converters) {
if (!(converter instanceof ConditionalGenericConverter) if (!(converter instanceof ConditionalGenericConverter) ||
|| ((ConditionalGenericConverter) converter).matches(sourceType, ((ConditionalGenericConverter) converter).matches(sourceType, targetType)) {
targetType)) {
return converter; return converter;
} }
} }

View File

@ -209,7 +209,7 @@ public class DefaultConversionTests {
} }
@Test @Test
public void testStringToEnumWithSubclss() throws Exception { public void testStringToEnumWithSubclass() throws Exception {
assertEquals(SubFoo.BAZ, conversionService.convert("BAZ", SubFoo.BAR.getClass())); assertEquals(SubFoo.BAZ, conversionService.convert("BAZ", SubFoo.BAR.getClass()));
} }
@ -224,7 +224,7 @@ public class DefaultConversionTests {
} }
public static enum Foo { public static enum Foo {
BAR, BAZ; BAR, BAZ
} }
public static enum SubFoo { public static enum SubFoo {