From 5a2c6a742307226e82d44d1e23ccae8302584b32 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 6 Oct 2022 10:56:42 +0300 Subject: [PATCH 1/2] Ensure that RESTEasy Reactive knows the proper return type when Flow is used --- .../resteasy/reactive/common/util/types/Types.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java index c347a46697d44..de58afdeb503d 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java @@ -180,16 +180,20 @@ public static Type getEffectiveReturnType(Type returnType) { if (returnType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) returnType; Type firstTypeArgument = type.getActualTypeArguments()[0]; - if (type.getRawType() == CompletionStage.class) { + Type rawType = type.getRawType(); + if (rawType == CompletionStage.class) { return getEffectiveReturnType(firstTypeArgument); } - if (type.getRawType() == Uni.class) { + if (rawType == Uni.class) { return getEffectiveReturnType(firstTypeArgument); } - if (type.getRawType() == Multi.class) { + if (rawType == Multi.class) { return getEffectiveReturnType(firstTypeArgument); } - if (type.getRawType() == RestResponse.class) { + if (rawType == RestResponse.class) { + return getEffectiveReturnType(firstTypeArgument); + } + if ("kotlinx.coroutines.flow.Flow".equals(rawType.getTypeName())) { // TODO: this is very ugly and we should probably use some an SPI in order to decouple return getEffectiveReturnType(firstTypeArgument); } return returnType; From 26f53a7ee7f956cae0083d216b89649876b79527 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 21 Sep 2022 18:26:42 +0300 Subject: [PATCH 2/2] Use proper type for serializing Kotlin response Fixes: #28096 --- .../serialization/KotlinSerializationMessageBodyWriter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/kotlin/serialization/KotlinSerializationMessageBodyWriter.kt b/extensions/resteasy-reactive/quarkus-resteasy-reactive-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/kotlin/serialization/KotlinSerializationMessageBodyWriter.kt index 134e5592e7ad6..866c528c7a4e3 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/kotlin/serialization/KotlinSerializationMessageBodyWriter.kt +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/kotlin/serialization/KotlinSerializationMessageBodyWriter.kt @@ -30,7 +30,7 @@ class KotlinSerializationMessageBodyWriter(private val json: Json) : AllWriteabl if (o is String) { // YUK: done in order to avoid adding extra quotes... entityStream.write(o.toByteArray(StandardCharsets.UTF_8)) } else { - json.encodeToStream(serializer(o.javaClass), o, entityStream) + json.encodeToStream(serializer(genericType), o, entityStream) } }