Support Kotlin extensions in web handlers

This commit restores support for Kotlin extensions in
web handlers, and adds support for invoking reflectively
suspending extension functions, as well as the other
features supported as of Spring Framework 6.1 like
value classes and default value for parameters.

Closes gh-31876
This commit is contained in:
Sébastien Deleuze
2023-12-21 12:15:26 +01:00
parent 5f8a031c22
commit 85cb6cc5fb
6 changed files with 130 additions and 25 deletions

View File

@@ -318,8 +318,11 @@ public class InvocableHandlerMethod extends HandlerMethod {
int index = 0;
for (KParameter parameter : function.getParameters()) {
switch (parameter.getKind()) {
case INSTANCE -> argMap.put(parameter, target);
case VALUE -> {
case INSTANCE:
argMap.put(parameter, target);
break;
case VALUE:
case EXTENSION_RECEIVER:
if (!parameter.isOptional() || args[index] != null) {
if (parameter.getType().getClassifier() instanceof KClass<?> kClass && kClass.isValue()) {
Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass);
@@ -332,7 +335,8 @@ public class InvocableHandlerMethod extends HandlerMethod {
}
}
index++;
}
break;
}
}
Object result = function.callBy(argMap);