From 8464ac90c713c7648e90224de606585ba6219cec Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Sat, 17 Apr 2010 20:22:30 +0000 Subject: [PATCH] promoted char sequence first --- .../core/convert/support/ObjectToStringConverter.java | 5 ++--- .../core/convert/support/DefaultConversionTests.java | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java index bea9463e0c..65614de1f1 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java @@ -43,9 +43,8 @@ final class ObjectToStringConverter implements ConditionalGenericConverter { public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { Class sourceClass = sourceType.getObjectType(); - return String.class.equals(sourceClass) || Number.class.isAssignableFrom(sourceClass) || - Boolean.class.equals(sourceClass) || Character.class.equals(sourceClass) || - CharSequence.class.isAssignableFrom(sourceClass) || StringWriter.class.isAssignableFrom(sourceClass) || + return CharSequence.class.isAssignableFrom(sourceClass) || Number.class.isAssignableFrom(sourceClass) || + Boolean.class.equals(sourceClass) || Character.class.equals(sourceClass) || StringWriter.class.isAssignableFrom(sourceClass) || sourceClass.isEnum() || ObjectToObjectConverter.hasValueOfMethodOrConstructor(sourceClass, String.class); } diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java index 8e8606a474..12d46fb9da 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java @@ -19,6 +19,7 @@ package org.springframework.core.convert.support; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.math.BigDecimal; @@ -218,6 +219,12 @@ public class DefaultConversionTests { assertEquals(Locale.ENGLISH, conversionService.convert("en", Locale.class)); } + @Test + public void testStringToString() { + String str = "test"; + assertSame(str, conversionService.convert(str, String.class)); + } + @Test public void testNumberToNumber() { assertEquals(Long.valueOf(1), conversionService.convert(Integer.valueOf(1), Long.class));