Is it possible to exclude a HTTP response from bei...
# ktor
n
Is it possible to exclude a HTTP response from being serialised? The code below triggers a InvalidMutabilityException:
Copy code
@UnstableDefault
private suspend fun runGenericPromQlQuery(host: String, port: Int, query: String): String =
    <http://httpClient.post|httpClient.post>("http://$host:$port") {
        contentType(ContentType.parse(FORM_URL_ENCODED))
        body = listOf("query" to query).formUrlEncode()
    }
Below is the stack trace:
Copy code
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@c15f78
        at kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable (0x2f7117)
        at kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception (0x2f0a25)
        at kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException (0x2f05e5)
        at kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException (0x31e765)
        at ThrowInvalidMutabilityException (0x31fe53)
        at MutationCheck (0x63f80e)
        at kfun:kotlin.collections.HashMap.<set-length>#internal (0x301ccd)
        at kfun:kotlin.collections.HashMap.addKey$stdlib(K)<http://kotlin.Int|kotlin.Int> (0x3062fb)
        at kfun:kotlin.collections.HashMap.put(K;V)V? (0x302cd9)
        at kfun:io.ktor.util.AttributesNative.put#internal (0x4dfc5f)
        at kfun:io.ktor.client.features.$addDefaultResponseValidation$lambda-1$lambda-0COROUTINE$18.invokeSuspend#internal (0x53a41c)
        at kfun:io.ktor.client.features.$addDefaultResponseValidation$lambda-1$lambda-0COROUTINE$18.invoke#internal (0x53aad2)
        at kfun:io.ktor.client.features.HttpCallValidator.$validateResponseCOROUTINE$24.invokeSuspend#internal (0x54326c)
        at kfun:io.ktor.client.features.HttpCallValidator.validateResponse#internal (0x543586)
        at kfun:io.ktor.client.features.HttpCallValidator.Companion.$install$lambda-1COROUTINE$23.invokeSuspend#internal (0x5461b0)
        at kfun:io.ktor.client.features.HttpCallValidator.Companion.$install$lambda-1COROUTINE$23.invoke#internal (0x546b0f)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dc1dd)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.proceed#internal (0x4db85e)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.execute#internal (0x4dbc61)
        at kfun:io.ktor.util.pipeline.Pipeline.execute(TContext;TSubject)TSubject (0x4d6a30)
        at kfun:io.ktor.client.call.HttpClientCall.$receiveCOROUTINE$13.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? (0x52d097)
        at kfun:io.ktor.client.call.HttpClientCall.receive(io.ktor.client.call.TypeInfo)kotlin.Any (0x52d706)
        at kfun:com.chapman.batteryMetricsExtractor.$runGenericPromQlQueryCOROUTINE$0.invokeSuspend#internal (0x5f2dc5)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x3125a8)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4dc8a8)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dc413)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4de42c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x312889)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4dc8a8)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dc413)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4de42c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x312889)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4dc8a8)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dc413)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4de42c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x312889)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4dc8a8)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dc413)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4de42c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x312889)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4dc8a8)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dc413)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4de42c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x312889)
        at kfun:kotlinx.coroutines.DispatchedTask.run() (0x3f9aca)
        at kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()kotlin.Long (0x3d5480)
        at kfun:kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal (0x406afe)
        at kfun:kotlinx.coroutines.runBlocking(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,T>){0<kotlin.Any?>}Generic (0x405be8)
        at kfun:kotlinx.coroutines.runBlocking$default(kotlin.coroutines.CoroutineContext?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,T>;<http://kotlin.Int|kotlin.Int>){0<kotlin.Any?>}Generic (0x406121)
        at kfun:com.chapman.batteryMetricsExtractor.main(kotlin.Array<kotlin.String>) (0x5f0848)
        at Konan_start (0x5f771b)
        at Init_and_run_start (0x61c08b)
        at __libc_start_main (0x7f291a21bb97)
        at  (0x2ac029)
        at  ((nil))
e
Hi @napperley, what do you mean by
being serialized
here? We should encode list somehow
n
I want to make it that the body from the HTTP response isn't being handled by the KotlinX Serialization library, and is just a String being returned (not converted to a custom data type).