Alexandre Brown
12/20/2021, 7:27 PMreturn response.body<MySerializableDataClass>()
does not work I get an error "No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class common.datasources.dtos.SerializablePredictV2ProtocolResponse"
Content-Type: application/json
But doing kotlinx.serialization.json.Json.decodeFromString(SerializablePredictV2ProtocolResponse.serializer(), response.bodyAsText())
works.
PS: I'm in a unit test environment, mocking the client engine as per documentation.
Any help is appreciated, thanks@Serializable
data class TestDataClass(
val a: String
)
MockEngine {
respond(
content = Json.encodeToString(TestDataClass("hello")),
status = HttpStatusCode.OK,
headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString())
)
}
val httpClient = HttpClient(engine) {
install(ContentNegotiation) {
Json
}
}
val response = <http://httpClient.post|httpClient.post>("<http://localhost:8080/myurl>")
val testResult = response.body<TestDataClass>()
Rustam Siniukov
12/20/2021, 8:28 PMinstall(ContentNegotiation) {
json()
}
instead. Calling just Json
doesn’t register serializer for ContentNegotiation
Alexandre Brown
12/20/2021, 8:32 PMRustam Siniukov
12/20/2021, 8:36 PMktor-serialization-kotlinx-json
?Alexandre Brown
12/20/2021, 8:36 PM