Skip to content

Commit 22dfe93

Browse files
committed
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
1 parent e9cdb3d commit 22dfe93

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,6 @@ public interface ConversionService {
5555
*/
5656
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
5757

58-
/**
59-
* Returns true if conversion between the sourceType and targetType can be bypassed.
60-
* More precisely this method will return true if objects of sourceType can be
61-
* converted to the targetType by returning the source object unchanged.
62-
* @param sourceType context about the source type to convert from (may be null if source is null)
63-
* @param targetType context about the target type to convert to (required)
64-
* @return true if conversion can be bypassed
65-
* @throws IllegalArgumentException if targetType is null
66-
* @since 3.2
67-
*/
68-
boolean canBypassConvert(Class<?> sourceType, Class<?> targetType);
69-
70-
/**
71-
* Returns true if conversion between the sourceType and targetType can be bypassed.
72-
* More precisely this method will return true if objects of sourceType can be
73-
* converted to the targetType by returning the source object unchanged.
74-
* @param sourceType context about the source type to convert from (may be null if source is null)
75-
* @param targetType context about the target type to convert to (required)
76-
* @return true if conversion can be bypassed
77-
* @throws IllegalArgumentException if targetType is null
78-
* @since 3.2
79-
*/
80-
boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
81-
8258
/**
8359
* Convert the source to targetType.
8460
* @param source the source object to convert (may be null)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
5555

5656
public Object convert(Object source, TypeDescriptor sourceType,
5757
TypeDescriptor targetType) {
58-
if (conversionService.canBypassConvert(sourceType.getElementTypeDescriptor(),
59-
targetType.getElementTypeDescriptor())) {
58+
if ((conversionService instanceof GenericConversionService)
59+
&& ((GenericConversionService) conversionService).canBypassConvert(
60+
sourceType.getElementTypeDescriptor(),
61+
targetType.getElementTypeDescriptor())) {
6062
return source;
6163
}
6264
List<Object> sourceList = Arrays.asList(ObjectUtils.toObjectArray(source));

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
129129
return (converter != null);
130130
}
131131

132-
public boolean canBypassConvert(Class<?> sourceType, Class<?> targetType) {
133-
Assert.notNull(targetType, "The targetType to convert to cannot be null");
134-
return canBypassConvert(sourceType != null ?
135-
TypeDescriptor.valueOf(sourceType) : null,
136-
TypeDescriptor.valueOf(targetType));
137-
}
138-
132+
/**
133+
* Returns true if conversion between the sourceType and targetType can be bypassed.
134+
* More precisely this method will return true if objects of sourceType can be
135+
* converted to the targetType by returning the source object unchanged.
136+
* @param sourceType context about the source type to convert from (may be null if source is null)
137+
* @param targetType context about the target type to convert to (required)
138+
* @return true if conversion can be bypassed
139+
* @throws IllegalArgumentException if targetType is null
140+
* @since 3.2
141+
*/
139142
public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
140143
Assert.notNull(targetType, "The targetType to convert to cannot be null");
141144
if (sourceType == null) {

0 commit comments

Comments
 (0)