From d13567bc8fbd9748d27b5df5fb3b2e98b37742cd Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Sun, 17 May 2009 03:09:59 +0000 Subject: [PATCH] added support for null conversion point type --- .../core/convert/support/GenericTypeConverter.java | 4 ++++ .../convert/support/GenericTypeConverterTests.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java index 1c11e4972e..f8c8c159b6 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java @@ -158,6 +158,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { throws ConverterNotFoundException { Assert.notNull(sourceClass, "The sourceType to convert from is required"); Assert.notNull(targetType, "The targetType to convert to is required"); + if (targetType.getType() == null) { + // TODO for Andy - is this correct way to handle the Null TypedValue? + return NoOpConversionExecutor.INSTANCE; + } ConversionPoint sourceType = ConversionPoint.valueOf(sourceClass); if (sourceType.isArray()) { if (targetType.isArray()) { diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java index f77125b64b..8fe7d493e6 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java @@ -80,7 +80,18 @@ public class GenericTypeConverterTests { public void convertNull() { assertNull(converter.convert(null, Integer.class)); } + + @Test + public void convertNullTargetClass() { + assertEquals("3", converter.convert("3", (Class)null)); + } + @Test + public void convertNullConversionPointType() { + assertEquals("3", converter.convert("3", ConversionPoint.NULL)); + } + + @Test public void convertWrongTypeArgument() { converter.addConverter(new StringToInteger());