From 2142cb32c2ed4a7850926991c076f8abfef3c9fa Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Tue, 8 Jul 2025 17:30:57 +0000 Subject: [PATCH] Close response properly in `core` utility `parseAs()` (#9591) --- core/src/main/kotlin/keiyoushi/utils/Json.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/kotlin/keiyoushi/utils/Json.kt b/core/src/main/kotlin/keiyoushi/utils/Json.kt index 7501d3e2b..86820ba36 100644 --- a/core/src/main/kotlin/keiyoushi/utils/Json.kt +++ b/core/src/main/kotlin/keiyoushi/utils/Json.kt @@ -10,19 +10,19 @@ import uy.kohesive.injekt.injectLazy val jsonInstance: Json by injectLazy() /** - * Parses and serializes the String as the type . + * Parses JSON string into an object of type [T]. */ inline fun String.parseAs(json: Json = jsonInstance): T = json.decodeFromString(this) /** - * Parse and serialize the response body as the type . + * Parses the response body into an object of type [T]. */ inline fun Response.parseAs(json: Json = jsonInstance): T = - json.decodeFromStream(body.byteStream()) + use { json.decodeFromStream(body.byteStream()) } /** - * Serializes the object to a JSON String. + * Serializes the object to a JSON string. */ inline fun T.toJsonString(json: Json = jsonInstance): String = json.encodeToString(this)