Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly request a serializer in writeTo() #24151

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
quarkus.kotlin-serialization.json.encode-defaults=true
quarkus.kotlin-serialization.json.pretty-print=true
quarkus.kotlin-serialization.json.pretty-print-indent=\ \
quarkus.kotlin-serialization.json.encode-defaults=true
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"}"""))
}
}

Expand All @@ -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!"}]"""))
}
}

Expand All @@ -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!"}"""))
}
}

Expand Down