From a59d139dfa4d6cdbac15d62128873d229cbddc7e Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sat, 21 Sep 2024 20:12:18 +0900 Subject: [PATCH] fix: fix `Json` configuration not applying when using customized `HttpClient` --- .../kotlin/builder/kord/KordBuilderUtil.kt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt b/core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt index a4640a05e82..d7ac3c65cf9 100644 --- a/core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt +++ b/core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt @@ -13,8 +13,15 @@ import kotlinx.serialization.json.Json internal fun HttpClientConfig<*>.defaultConfig() { expectSuccess = false + val json = Json { + encodeDefaults = false + allowStructuredMapKeys = true + ignoreUnknownKeys = true + isLenient = true + } + install(ContentNegotiation) { - json() + json(json) } install(WebSockets) } @@ -26,18 +33,8 @@ public fun HttpClient?.configure(): HttpClient { defaultConfig() } - val json = Json { - encodeDefaults = false - allowStructuredMapKeys = true - ignoreUnknownKeys = true - isLenient = true - } - return HttpClient(httpEngine()) { defaultConfig() - install(ContentNegotiation) { - json(json) - } } }