Browse Source

promoted char sequence first

pull/23217/head
Keith Donald 15 years ago
parent
commit
8464ac90c7
  1. 5
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java
  2. 7
      org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java

5
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToStringConverter.java

@ -43,9 +43,8 @@ final class ObjectToStringConverter implements ConditionalGenericConverter { @@ -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);
}

7
org.springframework.core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java

@ -19,6 +19,7 @@ package org.springframework.core.convert.support; @@ -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 { @@ -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));

Loading…
Cancel
Save