Skip to content

Commit 4dc2895

Browse files
philwebbcbeams
authored andcommitted
Refactor GenericConversionService
Refactor internal workings of GenericConversionService in order to better support future enhancements. This commit should not affect existing behavior. Issue: SPR-9927
1 parent 9bfe675 commit 4dc2895

File tree

3 files changed

+311
-330
lines changed

3 files changed

+311
-330
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424

2525
import org.springframework.core.MethodParameter;
26+
import org.springframework.util.Assert;
2627
import org.springframework.util.ClassUtils;
2728
import org.springframework.util.ObjectUtils;
2829

@@ -249,6 +250,23 @@ public TypeDescriptor narrow(Object value) {
249250
this.mapKeyTypeDescriptor, this.mapValueTypeDescriptor, this.annotations);
250251
}
251252

253+
/**
254+
* Cast this {@link TypeDescriptor} to a superclass or implemented interface
255+
* preserving annotations and nested type context.
256+
*
257+
* @param superType the super type to cast to (can be {@code null}
258+
* @return a new TypeDescriptor for the up-cast type
259+
* @throws IllegalArgumentException if this type is not assignable to the super-type
260+
*/
261+
public TypeDescriptor upcast(Class<?> superType) {
262+
if (superType == null) {
263+
return null;
264+
}
265+
Assert.isAssignable(superType, getType());
266+
return new TypeDescriptor(superType, this.elementTypeDescriptor,
267+
this.mapKeyTypeDescriptor, this.mapValueTypeDescriptor, this.annotations);
268+
}
269+
252270
/**
253271
* Returns the name of this type: the fully qualified class name.
254272
*/

0 commit comments

Comments
 (0)