fixed bug related to annotation driven formatting

This commit is contained in:
Keith Donald 2009-11-04 23:12:24 +00:00
parent ff39bc376f
commit 8a15486de3
3 changed files with 9 additions and 6 deletions

View File

@ -23,6 +23,9 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.joda.time.ReadableInstant; import org.joda.time.ReadableInstant;
import org.joda.time.ReadablePartial; import org.joda.time.ReadablePartial;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
@ -52,7 +55,7 @@ abstract class AbstractDateTimeAnnotationFormatterFactory<A extends Annotation>
DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation); DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation);
if (ReadableInstant.class.isAssignableFrom(propertyType)) { if (ReadableInstant.class.isAssignableFrom(propertyType)) {
return new ReadableInstantPrinter(formatter); return new ReadableInstantPrinter(formatter);
} else if (ReadablePartial.class.equals(propertyType)) { } else if (ReadablePartial.class.isAssignableFrom(propertyType)) {
return new ReadablePartialPrinter(formatter); return new ReadablePartialPrinter(formatter);
} else if (Calendar.class.isAssignableFrom(propertyType)) { } else if (Calendar.class.isAssignableFrom(propertyType)) {
// assumes Calendar->ReadableInstant converter is registered // assumes Calendar->ReadableInstant converter is registered
@ -78,8 +81,10 @@ abstract class AbstractDateTimeAnnotationFormatterFactory<A extends Annotation>
private Set<Class<?>> createFieldTypes() { private Set<Class<?>> createFieldTypes() {
Set<Class<?>> propertyTypes = new HashSet<Class<?>>(5); Set<Class<?>> propertyTypes = new HashSet<Class<?>>(5);
propertyTypes.add(ReadableInstant.class); propertyTypes.add(LocalDate.class);
propertyTypes.add(ReadablePartial.class); propertyTypes.add(LocalTime.class);
propertyTypes.add(LocalDateTime.class);
propertyTypes.add(DateTime.class);
propertyTypes.add(Date.class); propertyTypes.add(Date.class);
propertyTypes.add(Calendar.class); propertyTypes.add(Calendar.class);
propertyTypes.add(Long.class); propertyTypes.add(Long.class);

View File

@ -88,7 +88,7 @@ public class FormattingConversionService implements FormatterRegistry, Conversio
return sourceFieldType.getAnnotation(annotationType) != null; return sourceFieldType.getAnnotation(annotationType) != null;
} }
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Printer<?> printer = annotationFormatterFactory.getPrinter(sourceType.getAnnotation(annotationType), targetType.getType()); Printer<?> printer = annotationFormatterFactory.getPrinter(sourceType.getAnnotation(annotationType), sourceType.getType());
return new PrinterConverter(printer, conversionService).convert(source, sourceType, targetType); return new PrinterConverter(printer, conversionService).convert(source, sourceType, targetType);
} }
public String toString() { public String toString() {

View File

@ -12,7 +12,6 @@ import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime; import org.joda.time.LocalTime;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -60,7 +59,6 @@ public class JodaTimeFormattingTests {
} }
@Test @Test
@Ignore
public void testBindLocalDateAnnotated() { public void testBindLocalDateAnnotated() {
MutablePropertyValues propertyValues = new MutablePropertyValues(); MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.addPropertyValue("localDateAnnotated", "Oct 31, 2009"); propertyValues.addPropertyValue("localDateAnnotated", "Oct 31, 2009");