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
This commit is contained in:
Phillip Webb 2012-10-30 14:00:12 -07:00
parent e9cdb3d24e
commit 22dfe93f2f
3 changed files with 14 additions and 33 deletions

View File

@ -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)

View File

@ -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<Object> sourceList = Arrays.asList(ObjectUtils.toObjectArray(source));

View File

@ -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) {