Polishing.
Use ResolvableType for type assignability check when resolving Type from a KType. See #2324.
This commit is contained in:
@@ -33,6 +33,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.SimplePropertyHandler;
|
||||
@@ -277,11 +278,7 @@ class KotlinCopyMethod {
|
||||
|
||||
Type parameterType = ReflectJvmMapping.getJavaType(source);
|
||||
|
||||
if (parameterType instanceof Class) {
|
||||
return target.isAssignableFrom((Class<?>) parameterType);
|
||||
}
|
||||
|
||||
return false;
|
||||
return ResolvableType.forClass(target).isAssignableFrom(ResolvableType.forType(parameterType));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,4 +72,12 @@ class KotlinCopyMethodUnitTests {
|
||||
assertThat(copyMethod.shouldUsePublicCopyMethod(mappingContext.getRequiredPersistentEntity(DataClassKt.class)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test // #2324
|
||||
void shouldDetermineCopyMethodForParametrizedType() {
|
||||
|
||||
Optional<KotlinCopyMethod> copyMethod = KotlinCopyMethod.findCopyMethod(ImmutableKotlinPerson.class);
|
||||
|
||||
assertThat(copyMethod).isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mapping.model
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
||||
@@ -59,3 +60,8 @@ data class WithCustomCopyMethod(
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
data class ImmutableKotlinPerson(
|
||||
@Id val name: String,
|
||||
val wasOnboardedBy: List<ImmutableKotlinPerson>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user