From 22dfe93f2fabfcfaf60a957dc8b2e308b2dc020b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 30 Oct 2012 14:00:12 -0700 Subject: [PATCH] Revert ConversionService SPI interface Remove canBypassConvert() methods from the ConversionService SPI interface, restoring it to the previous Spring 3.1 incarnation. Bypassing conversion is now only supported when using a GenericConversionService. Issue: SPR-9566 --- .../core/convert/ConversionService.java | 24 ------------------- .../support/ArrayToArrayConverter.java | 6 +++-- .../support/GenericConversionService.java | 17 +++++++------ 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java index 8dd40490e9b..84756278b21 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java @@ -55,30 +55,6 @@ public interface ConversionService { */ boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType); - /** - * Returns true if conversion between the sourceType and targetType can be bypassed. - * More precisely this method will return true if objects of sourceType can be - * converted to the targetType by returning the source object unchanged. - * @param sourceType context about the source type to convert from (may be null if source is null) - * @param targetType context about the target type to convert to (required) - * @return true if conversion can be bypassed - * @throws IllegalArgumentException if targetType is null - * @since 3.2 - */ - boolean canBypassConvert(Class sourceType, Class targetType); - - /** - * Returns true if conversion between the sourceType and targetType can be bypassed. - * More precisely this method will return true if objects of sourceType can be - * converted to the targetType by returning the source object unchanged. - * @param sourceType context about the source type to convert from (may be null if source is null) - * @param targetType context about the target type to convert to (required) - * @return true if conversion can be bypassed - * @throws IllegalArgumentException if targetType is null - * @since 3.2 - */ - boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType); - /** * Convert the source to targetType. * @param source the source object to convert (may be null) diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java index 9a20642a176..2b52d25b174 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java @@ -55,8 +55,10 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter { public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { - if (conversionService.canBypassConvert(sourceType.getElementTypeDescriptor(), - targetType.getElementTypeDescriptor())) { + if ((conversionService instanceof GenericConversionService) + && ((GenericConversionService) conversionService).canBypassConvert( + sourceType.getElementTypeDescriptor(), + targetType.getElementTypeDescriptor())) { return source; } List sourceList = Arrays.asList(ObjectUtils.toObjectArray(source)); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index fe86c128dab..579fa617f18 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -129,13 +129,16 @@ public class GenericConversionService implements ConfigurableConversionService { return (converter != null); } - public boolean canBypassConvert(Class sourceType, Class targetType) { - Assert.notNull(targetType, "The targetType to convert to cannot be null"); - return canBypassConvert(sourceType != null ? - TypeDescriptor.valueOf(sourceType) : null, - TypeDescriptor.valueOf(targetType)); - } - + /** + * Returns true if conversion between the sourceType and targetType can be bypassed. + * More precisely this method will return true if objects of sourceType can be + * converted to the targetType by returning the source object unchanged. + * @param sourceType context about the source type to convert from (may be null if source is null) + * @param targetType context about the target type to convert to (required) + * @return true if conversion can be bypassed + * @throws IllegalArgumentException if targetType is null + * @since 3.2 + */ public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) { Assert.notNull(targetType, "The targetType to convert to cannot be null"); if (sourceType == null) {