diff --git a/fuel-kotlinx-serialization/src/appleMain/kotlin/fuel/serialization/ResponseExtensions.kt b/fuel-kotlinx-serialization/src/appleMain/kotlin/fuel/serialization/ResponseExtensions.kt index ccaec345..389bf715 100644 --- a/fuel-kotlinx-serialization/src/appleMain/kotlin/fuel/serialization/ResponseExtensions.kt +++ b/fuel-kotlinx-serialization/src/appleMain/kotlin/fuel/serialization/ResponseExtensions.kt @@ -6,8 +6,8 @@ import fuel.HttpResponse import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.json.Json -public fun HttpResponse.toJson( - json: Json = Json { allowStructuredMapKeys = true }, +public actual fun HttpResponse.toJson( + json: Json, deserializationStrategy: DeserializationStrategy ): Result = runCatching { body?.let { json.decodeFromString(deserializationStrategy, it) } diff --git a/fuel-kotlinx-serialization/src/commonMain/kotlin/fuel/serialization/ResponseExtensions.kt b/fuel-kotlinx-serialization/src/commonMain/kotlin/fuel/serialization/ResponseExtensions.kt new file mode 100644 index 00000000..e0dd4dcd --- /dev/null +++ b/fuel-kotlinx-serialization/src/commonMain/kotlin/fuel/serialization/ResponseExtensions.kt @@ -0,0 +1,11 @@ +package fuel.serialization + +import com.github.kittinunf.result.Result +import fuel.HttpResponse +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.json.Json + +public expect fun HttpResponse.toJson( + json: Json = Json, + deserializationStrategy: DeserializationStrategy +): Result diff --git a/fuel-kotlinx-serialization/src/jsMain/kotlin/fuel/serialization/ResponseExtensions.kt b/fuel-kotlinx-serialization/src/jsMain/kotlin/fuel/serialization/ResponseExtensions.kt index 90bcc2e2..f519db16 100644 --- a/fuel-kotlinx-serialization/src/jsMain/kotlin/fuel/serialization/ResponseExtensions.kt +++ b/fuel-kotlinx-serialization/src/jsMain/kotlin/fuel/serialization/ResponseExtensions.kt @@ -6,8 +6,8 @@ import fuel.HttpResponse import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.json.Json -public fun HttpResponse.toJson( - json: Json = Json { allowStructuredMapKeys = true }, +public actual fun HttpResponse.toJson( + json: Json, deserializationStrategy: DeserializationStrategy ): Result = runCatching { json.decodeFromString(deserializationStrategy, response?.json().toString()) diff --git a/fuel-kotlinx-serialization/src/jvmMain/kotlin/fuel/serialization/ResponseExtensions.kt b/fuel-kotlinx-serialization/src/jvmMain/kotlin/fuel/serialization/ResponseExtensions.kt index 885c0946..ae27ac69 100644 --- a/fuel-kotlinx-serialization/src/jvmMain/kotlin/fuel/serialization/ResponseExtensions.kt +++ b/fuel-kotlinx-serialization/src/jvmMain/kotlin/fuel/serialization/ResponseExtensions.kt @@ -6,8 +6,8 @@ import fuel.HttpResponse import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.json.Json -public fun HttpResponse.toJson( - json: Json = Json { allowStructuredMapKeys = true }, +public actual fun HttpResponse.toJson( + json: Json, deserializationStrategy: DeserializationStrategy ): Result = runCatching { json.decodeFromString(deserializationStrategy, body.string())