From 8a15486de3b61b293391af50402d92fa1734abec Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 4 Nov 2009 23:12:24 +0000 Subject: [PATCH] fixed bug related to annotation driven formatting --- .../AbstractDateTimeAnnotationFormatterFactory.java | 11 ++++++++--- .../format/support/FormattingConversionService.java | 2 +- .../ui/format/jodatime/JodaTimeFormattingTests.java | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/AbstractDateTimeAnnotationFormatterFactory.java b/org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/AbstractDateTimeAnnotationFormatterFactory.java index 6c48799f40..8c8b4fe06a 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/AbstractDateTimeAnnotationFormatterFactory.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/format/jodatime/AbstractDateTimeAnnotationFormatterFactory.java @@ -23,6 +23,9 @@ import java.util.HashSet; import java.util.Set; 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.ReadablePartial; import org.joda.time.format.DateTimeFormatter; @@ -52,7 +55,7 @@ abstract class AbstractDateTimeAnnotationFormatterFactory DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation); if (ReadableInstant.class.isAssignableFrom(propertyType)) { return new ReadableInstantPrinter(formatter); - } else if (ReadablePartial.class.equals(propertyType)) { + } else if (ReadablePartial.class.isAssignableFrom(propertyType)) { return new ReadablePartialPrinter(formatter); } else if (Calendar.class.isAssignableFrom(propertyType)) { // assumes Calendar->ReadableInstant converter is registered @@ -78,8 +81,10 @@ abstract class AbstractDateTimeAnnotationFormatterFactory private Set> createFieldTypes() { Set> propertyTypes = new HashSet>(5); - propertyTypes.add(ReadableInstant.class); - propertyTypes.add(ReadablePartial.class); + propertyTypes.add(LocalDate.class); + propertyTypes.add(LocalTime.class); + propertyTypes.add(LocalDateTime.class); + propertyTypes.add(DateTime.class); propertyTypes.add(Date.class); propertyTypes.add(Calendar.class); propertyTypes.add(Long.class); diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionService.java b/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionService.java index d3df33ff4f..0416b7f1e5 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionService.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionService.java @@ -88,7 +88,7 @@ public class FormattingConversionService implements FormatterRegistry, Conversio return sourceFieldType.getAnnotation(annotationType) != null; } 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); } public String toString() { diff --git a/org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java b/org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java index 170ae4a3ab..4b564c01a3 100644 --- a/org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java +++ b/org.springframework.context/src/test/java/org/springframework/ui/format/jodatime/JodaTimeFormattingTests.java @@ -12,7 +12,6 @@ import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.MutablePropertyValues; import org.springframework.context.i18n.LocaleContextHolder; @@ -60,7 +59,6 @@ public class JodaTimeFormattingTests { } @Test - @Ignore public void testBindLocalDateAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("localDateAnnotated", "Oct 31, 2009");