From 63fdd729f58a1591864ddb867a947f503f0c58e7 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 10 Jun 2022 16:12:38 -0700 Subject: [PATCH] Refine conversion service type check Update fix to account for primitive types. See gh-28592 --- .../boot/context/properties/bind/BindConverter.java | 3 ++- .../context/properties/WithPublicObjectToObjectMethod.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java index 0e477296d9..430270b89c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java @@ -42,6 +42,7 @@ import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.core.convert.support.GenericConversionService; +import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; /** @@ -107,7 +108,7 @@ final class BindConverter { try { if (delegate.canConvert(sourceType, targetType)) { Object converted = delegate.convert(source, sourceType, targetType); - if (targetType.getType().isInstance(converted)) { + if (ClassUtils.isAssignableValue(targetType.getType(), converted)) { return converted; } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/WithPublicObjectToObjectMethod.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/WithPublicObjectToObjectMethod.java index f3a5b167c3..06fed65459 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/WithPublicObjectToObjectMethod.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/WithPublicObjectToObjectMethod.java @@ -40,4 +40,4 @@ public class WithPublicObjectToObjectMethod { return Optional.of(new WithPublicObjectToObjectMethod(value)); } -} \ No newline at end of file +}