diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java index 50cf3c432ac..369615a8805 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java @@ -18,9 +18,8 @@ package org.springframework.expression.spel.support; import org.springframework.core.convert.ConvertException; import org.springframework.core.convert.ConverterNotFoundException; -import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.core.convert.service.DefaultConversionService; +import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeConverter; import org.springframework.expression.spel.SpelException; @@ -34,28 +33,31 @@ import org.springframework.util.Assert; */ public class StandardTypeConverter implements TypeConverter { - private ConversionService conversionService; + private org.springframework.core.convert.TypeConverter typeConverter; public StandardTypeConverter() { - conversionService = new DefaultConversionService(); + this.typeConverter = new DefaultConversionService(); } - public StandardTypeConverter(ConversionService conversionService) { - Assert.notNull(conversionService, "The conversionService must not be null"); - this.conversionService = conversionService; + public StandardTypeConverter(org.springframework.core.convert.TypeConverter typeConverter) { + Assert.notNull(typeConverter, "TypeConverter must not be null"); + this.typeConverter = typeConverter; } @SuppressWarnings("unchecked") public T convertValue(Object value, Class targetType) throws EvaluationException { - return (T) convertValue(value,TypeDescriptor.valueOf(targetType)); + return (T) convertValue(value, TypeDescriptor.valueOf(targetType)); } + @SuppressWarnings("unchecked") public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException { try { - return conversionService.convert(value, typeDescriptor); - } catch (ConverterNotFoundException cenfe) { + return this.typeConverter.convert(value, typeDescriptor); + } + catch (ConverterNotFoundException cenfe) { throw new SpelException(cenfe, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString()); - } catch (ConvertException ce) { + } + catch (ConvertException ce) { throw new SpelException(ce, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString()); } } @@ -65,7 +67,7 @@ public class StandardTypeConverter implements TypeConverter { } public boolean canConvert(Class sourceType, TypeDescriptor targetType) { - return conversionService.canConvert(sourceType, targetType); + return this.typeConverter.canConvert(sourceType, targetType); } } diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java index 03cfa900ce1..1d66d5c0777 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java @@ -20,8 +20,8 @@ import java.util.ArrayList; import java.util.List; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.core.convert.service.DefaultConversionService; -import org.springframework.core.convert.service.GenericConversionService; +import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.core.convert.support.GenericConversionService; import org.springframework.expression.EvaluationException; import org.springframework.expression.Expression; import org.springframework.expression.TypeConverter; @@ -64,14 +64,14 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas // ArrayList containing List to List Class clazz = typeDescriptorForListOfString.getElementType(); assertEquals(String.class,clazz); - List l = (List) tcs.convert(listOfInteger, typeDescriptorForListOfString); + List l = (List) tcs.convertValue(listOfInteger, typeDescriptorForListOfString); assertNotNull(l); // ArrayList containing List to List clazz = typeDescriptorForListOfInteger.getElementType(); assertEquals(Integer.class,clazz); - l = (List) tcs.convert(listOfString, typeDescriptorForListOfString); + l = (List) tcs.convertValue(listOfString, typeDescriptorForListOfString); assertNotNull(l); } @@ -89,29 +89,29 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas /** - * Type convertor that uses the core conversion service. + * Type converter that uses the core conversion service. */ - private static class TypeConvertorUsingConversionService extends DefaultConversionService implements TypeConverter { + private static class TypeConvertorUsingConversionService implements TypeConverter { + + private final DefaultConversionService service = new DefaultConversionService(); public boolean canConvert(Class sourceType, Class targetType) { - return super.canConvert(sourceType, TypeDescriptor.valueOf(targetType)); + return this.service.canConvert(sourceType, TypeDescriptor.valueOf(targetType)); } public boolean canConvert(Class sourceType, TypeDescriptor typeDescriptor) { - return super.canConvert(sourceType, typeDescriptor); + return this.service.canConvert(sourceType, typeDescriptor); } @SuppressWarnings("unchecked") public T convertValue(Object value, Class targetType) throws EvaluationException { - return (T)super.convert(value,TypeDescriptor.valueOf(targetType)); + return (T) this.service.convert(value,TypeDescriptor.valueOf(targetType)); } @SuppressWarnings("unchecked") - public Object convertValue(Object value, TypeDescriptor typeDescriptor) - throws EvaluationException { - return super.convert(value, typeDescriptor); + public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException { + return this.service.convert(value, typeDescriptor); } - } }