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 28650279d1830..c74c5f3b24d26 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 @@ -27,7 +27,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(o, entityStream) + json.encodeToStream(serializer(o.javaClass) , o, entityStream) } } diff --git a/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt b/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt index aa79185c7e35e..c3eddcab2088d 100644 --- a/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt +++ b/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt @@ -2,6 +2,7 @@ package io.quarkus.it.kotser import io.quarkus.it.kotser.model.Person import io.quarkus.runtime.annotations.RegisterForReflection +import kotlinx.coroutines.flow.flowOf import java.lang.reflect.Method import javax.ws.rs.Consumes import javax.ws.rs.GET @@ -15,6 +16,10 @@ import kotlin.reflect.jvm.javaMethod @Path("/") @RegisterForReflection class GreetingResource { + @Path("flow") + @GET + @Produces(MediaType.APPLICATION_JSON) + fun flowHello() = flowOf(Person("Jim Halpert")) @GET @Produces(MediaType.APPLICATION_JSON) diff --git a/integration-tests/kotlin-serialization/src/main/resources/application.properties b/integration-tests/kotlin-serialization/src/main/resources/application.properties index 86df10fe75526..4dadb74e15205 100644 --- a/integration-tests/kotlin-serialization/src/main/resources/application.properties +++ b/integration-tests/kotlin-serialization/src/main/resources/application.properties @@ -1,3 +1 @@ -quarkus.kotlin-serialization.json.encode-defaults=true -quarkus.kotlin-serialization.json.pretty-print=true -quarkus.kotlin-serialization.json.pretty-print-indent=\ \ \ No newline at end of file +quarkus.kotlin-serialization.json.encode-defaults=true \ No newline at end of file diff --git a/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt b/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt index 3ba3015b9b402..5054b2afbe8af 100644 --- a/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt +++ b/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt @@ -12,20 +12,24 @@ import javax.ws.rs.core.MediaType @QuarkusTest open class ResourceTest { + @Test + fun testGetFlow() { + When { + get("/flow") + } Then { + statusCode(200) + body(`is`("""[{"name":"Jim Halpert","defaulted":"hi there!"}]""")) + } + } + @Test fun testGet() { - When { - get("/") - } Then { - statusCode(200) - body(`is`( - """ - { - "name": "Jim Halpert", - "defaulted": "hi there!" - }""".trimIndent() - )) - } + When { + get("/") + } Then { + statusCode(200) + body(`is`("""{"name":"Jim Halpert","defaulted":"hi there!"}""")) + } } @Test @@ -34,13 +38,7 @@ open class ResourceTest { get("/suspend") } Then { statusCode(200) - body(`is`( - """ - { - "name": "Jim Halpert", - "defaulted": "hi there!" - }""".trimIndent() - )) + body(`is`("""{"name":"Jim Halpert","defaulted":"hi there!"}""")) } } @@ -50,15 +48,7 @@ open class ResourceTest { get("/suspendList") } Then { statusCode(200) - body(`is`( - """ -[ - { - "name": "Jim Halpert", - "defaulted": "hi there!" - } -] -""".trimIndent())) + body(`is`("""[{"name":"Jim Halpert","defaulted":"hi there!"}]""")) } } @@ -71,11 +61,7 @@ open class ResourceTest { post("/") } Then { statusCode(200) - body(`is`(""" - { - "name": "Pam Halpert", - "defaulted": "hi there!" - }""".trimIndent())) + body(`is`("""{"name":"Pam Halpert","defaulted":"hi there!"}""")) } }