Nikola
06/19/2025, 11:58 AMdata
coming from the transformBody is always an instance of OutgoingContent
or OutputStreamContent
. I use jackson for serialization, could that be the reason I am unable to capture json?Aleksei Tirman [JB]
06/19/2025, 12:09 PMJacksonConverter
uses OutputStreamContent
class as a response body. If the JSON data your server responds with is relatively small, you can turn off body streaming to respond with a TextContent
that has the text
property of type String
.
install(ContentNegotiation) {
jackson(streamRequestBody = false)
}
Nikola
06/19/2025, 12:11 PMAleksei Tirman [JB]
06/19/2025, 1:08 PMOutputStreamContent
while leaving the original body unconsumed:
val plugin = createApplicationPlugin("plugin") {
onCallRespond { call ->
transformBody { data ->
if (data is OutputStreamContent) {
val channel = ByteChannel()
call.launch {
data.writeTo(channel)
channel.close()
}
val (origChannel, newChannel) = channel.split(call)
// Read JSON
println(newChannel.readRemaining().readText())
origChannel
} else {
data
}
}
}
}
Nikola
06/19/2025, 1:09 PM