diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java index 89e7bb08baf..8872b8d1ca0 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java +++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java @@ -36,6 +36,7 @@ import org.springframework.format.Parser; import org.springframework.format.Printer; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; +import org.springframework.util.StringUtils; /** * Formats fields annotated with the {@link DateTimeFormat} annotation. @@ -98,7 +99,7 @@ public final class DateTimeFormatAnnotationFormatterFactory implements Annotatio } private DateTimeFormatter configureDateTimeFormatterFrom(DateTimeFormat annotation) { - if (!annotation.pattern().isEmpty()) { + if (StringUtils.hasLength(annotation.pattern())) { return forPattern(annotation.pattern()); } else if (annotation.iso() != ISO.NONE) { diff --git a/org.springframework.context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java b/org.springframework.context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java index c5baf995b12..09da26668b6 100644 --- a/org.springframework.context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java +++ b/org.springframework.context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java @@ -28,6 +28,7 @@ import org.springframework.format.Parser; import org.springframework.format.Printer; import org.springframework.format.annotation.NumberFormat; import org.springframework.format.annotation.NumberFormat.Style; +import org.springframework.util.StringUtils; /** * Formats fields annotated with the {@link NumberFormat} annotation. @@ -74,7 +75,7 @@ public final class NumberFormatAnnotationFormatterFactory implements AnnotationF } private Formatter configureFormatterFrom(NumberFormat annotation, Class fieldType) { - if (!annotation.pattern().isEmpty()) { + if (StringUtils.hasLength(annotation.pattern())) { return new NumberFormatter(annotation.pattern()); } else {