DATACMNS-1170 - Fallback to default constructor discovery for Kotlin classes without primary constructor.

We now fall back to default preferred constructor discovery if a Kotlin class has no primary constructor and no preferred constructor is resolved. Previously, primary constructor resolution yielded no result (returned null) which caused the subsequent Java constructor lookup to fail.

Original pull request: #244.
This commit is contained in:
Mark Paluch
2017-09-22 11:43:16 +02:00
committed by Oliver Gierke
parent 93c65c02fe
commit 041c18bef9
2 changed files with 24 additions and 0 deletions

View File

@@ -166,6 +166,11 @@ public interface PreferredConstructorDiscoverer<T, P extends PersistentProperty<
KFunction<T> primaryConstructor = KClasses
.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(type.getType()));
if (primaryConstructor == null) {
return DEFAULT.discover(type, entity);
}
Constructor<T> javaConstructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
return javaConstructor != null ? buildPreferredConstructor(javaConstructor, type, entity) : null;