diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index e4519ee27980628813be238342a3e4048d07717b..894dfcd0234fd06ff05300275e18e91e56241b8d 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -172,7 +172,13 @@ public class GenericConversionService implements ConversionService, ConverterReg } GenericConverter converter = getConverter(sourceType, targetType); if (converter == null) { - throw new ConverterNotFoundException(sourceType, targetType); + if (targetType.getType().isInstance(source)) { + logger.debug("No converter found - returning assignable source object as-is"); + return source; + } + else { + throw new ConverterNotFoundException(sourceType, targetType); + } } Object result = ConversionUtils.invokeConverter(converter, source, sourceType, targetType); if (logger.isDebugEnabled()) { diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/standard/PropertiesConversionSpelTests.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/standard/PropertiesConversionSpelTests.java index 6c1c47f508754277680d5d0639d54f0f5a1facfa..ebac11450efda4beff0c10a141c955bab6752893 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/standard/PropertiesConversionSpelTests.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/standard/PropertiesConversionSpelTests.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.UUID; import org.junit.Test; @@ -61,12 +62,26 @@ public class PropertiesConversionSpelTests { assertEquals("123", result); } - @Test // questionable, but this passes with 3.0.2.RELEASE + @Test public void mapWithNonStringValue() { Map map = new HashMap(); map.put("x", "1"); map.put("y", 2); map.put("z", "3"); + map.put("a", new UUID(1, 1)); + Expression expression = parser.parseExpression("foo(#props)"); + StandardEvaluationContext context = new StandardEvaluationContext(); + context.setVariable("props", map); + String result = expression.getValue(context, new TestBean(), String.class); + assertEquals("1null3", result); + } + + @Test + public void customMapWithNonStringValue() { + CustomMap map = new CustomMap(); + map.put("x", "1"); + map.put("y", 2); + map.put("z", "3"); Expression expression = parser.parseExpression("foo(#props)"); StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariable("props", map); @@ -83,4 +98,9 @@ public class PropertiesConversionSpelTests { } } + + @SuppressWarnings("serial") + private static class CustomMap extends HashMap { + } + }