Browse Source

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
pull/99/merge
Phillip Webb 14 years ago
parent
commit
22dfe93f2f
  1. 24
      spring-core/src/main/java/org/springframework/core/convert/ConversionService.java
  2. 6
      spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java
  3. 17
      spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

24
spring-core/src/main/java/org/springframework/core/convert/ConversionService.java

@ -55,30 +55,6 @@ public interface ConversionService {
*/ */
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType); 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. * Convert the source to targetType.
* @param source the source object to convert (may be null) * @param source the source object to convert (may be null)

6
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, public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) { TypeDescriptor targetType) {
if (conversionService.canBypassConvert(sourceType.getElementTypeDescriptor(), if ((conversionService instanceof GenericConversionService)
targetType.getElementTypeDescriptor())) { && ((GenericConversionService) conversionService).canBypassConvert(
sourceType.getElementTypeDescriptor(),
targetType.getElementTypeDescriptor())) {
return source; return source;
} }
List<Object> sourceList = Arrays.asList(ObjectUtils.toObjectArray(source)); List<Object> sourceList = Arrays.asList(ObjectUtils.toObjectArray(source));

17
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

@ -129,13 +129,16 @@ public class GenericConversionService implements ConfigurableConversionService {
return (converter != null); return (converter != null);
} }
public boolean canBypassConvert(Class<?> sourceType, Class<?> targetType) { /**
Assert.notNull(targetType, "The targetType to convert to cannot be null"); * Returns true if conversion between the sourceType and targetType can be bypassed.
return canBypassConvert(sourceType != null ? * More precisely this method will return true if objects of sourceType can be
TypeDescriptor.valueOf(sourceType) : null, * converted to the targetType by returning the source object unchanged.
TypeDescriptor.valueOf(targetType)); * @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) { public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
Assert.notNull(targetType, "The targetType to convert to cannot be null"); Assert.notNull(targetType, "The targetType to convert to cannot be null");
if (sourceType == null) { if (sourceType == null) {

Loading…
Cancel
Save