|
18 | 18 |
|
19 | 19 | import java.lang.reflect.InvocationTargetException; |
20 | 20 | import java.lang.reflect.Method; |
| 21 | +import java.lang.reflect.Modifier; |
21 | 22 | import java.util.Map; |
22 | 23 | import java.util.Objects; |
23 | 24 |
|
|
40 | 41 | import kotlinx.coroutines.reactor.MonoKt; |
41 | 42 | import kotlinx.coroutines.reactor.ReactorFlowKt; |
42 | 43 | import org.reactivestreams.Publisher; |
| 44 | +import org.springframework.util.ReflectionUtils; |
43 | 45 | import reactor.core.publisher.Flux; |
44 | 46 | import reactor.core.publisher.Mono; |
45 | 47 |
|
|
55 | 57 | */ |
56 | 58 | public abstract class CoroutinesUtils { |
57 | 59 |
|
| 60 | + private static final ReflectionUtils.MethodFilter boxImplFilter = |
| 61 | + (method -> method.isSynthetic() && Modifier.isStatic(method.getModifiers()) && method.getName().equals("box-impl")); |
| 62 | + |
58 | 63 | /** |
59 | 64 | * Convert a {@link Deferred} instance to a {@link Mono}. |
60 | 65 | */ |
@@ -115,7 +120,14 @@ public static Publisher<?> invokeSuspendingFunction(CoroutineContext context, Me |
115 | 120 | case INSTANCE -> argMap.put(parameter, target); |
116 | 121 | case VALUE -> { |
117 | 122 | if (!parameter.isOptional() || args[index] != null) { |
118 | | - argMap.put(parameter, args[index]); |
| 123 | + if (parameter.getType().getClassifier() instanceof KClass<?> kClass && kClass.isValue()) { |
| 124 | + Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass); |
| 125 | + Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(javaClass, boxImplFilter); |
| 126 | + Assert.state(methods.length == 1, "Unable to find a single box-impl synthetic static method in " + javaClass.getName()); |
| 127 | + argMap.put(parameter, ReflectionUtils.invokeMethod(methods[0], null, args[index])); |
| 128 | + } else { |
| 129 | + argMap.put(parameter, args[index]); |
| 130 | + } |
119 | 131 | } |
120 | 132 | index++; |
121 | 133 | } |
|
0 commit comments