Merge branch '6.2.x'
# Conflicts: # spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
This commit is contained in:
@@ -341,6 +341,13 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
conditionalConverter.matches(sourceType, targetType);
|
||||
}
|
||||
|
||||
public boolean matchesFallback(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return (this.typeInfo.getTargetType() == targetType.getObjectType() &&
|
||||
this.targetType.hasUnresolvableGenerics() &&
|
||||
(!(this.converter instanceof ConditionalConverter conditionalConverter) ||
|
||||
conditionalConverter.matches(sourceType, targetType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
@@ -610,12 +617,20 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
|
||||
public @Nullable GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
// Look for proper match among all converters (taking full generics into account)
|
||||
for (GenericConverter converter : this.converters) {
|
||||
if (!(converter instanceof ConditionalGenericConverter genericConverter) ||
|
||||
genericConverter.matches(sourceType, targetType)) {
|
||||
return converter;
|
||||
}
|
||||
}
|
||||
// Fallback to pre-6.2.3 behavior: accept Class match for unresolvable generics
|
||||
for (GenericConverter converter : this.converters) {
|
||||
if (converter instanceof ConverterAdapter converterAdapter &&
|
||||
converterAdapter.matchesFallback(sourceType, targetType)) {
|
||||
return converter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user