Skip to content

Commit

Permalink
Merge pull request #24151 from evanchooly/main
Browse files Browse the repository at this point in the history
Explicitly request a serializer in writeTo()
  • Loading branch information
geoand authored Mar 8, 2022
2 parents 5a9db9d + a011e92 commit b98c54c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
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

0 comments on commit b98c54c

Please sign in to comment.