Skip to content

Commit

Permalink
🐛[Bug] [Extension] Fix KotlinX serialization problem (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
kittinunf authored Apr 5, 2020
1 parent 84e4ab7 commit 0fff191
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object Fuel {

// Core dependencies
object Kotlin {
const val version = "1.3.61"
const val version = "1.3.70"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"
const val plugin = "kotlin"
const val androidPlugin = "kotlin-android"
Expand Down Expand Up @@ -139,7 +139,7 @@ object KotlinX {
}

object Serialization {
const val version = "0.14.0"
const val version = "0.20.0"
const val dependency = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$version"
const val plugin = "kotlinx-serialization"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,51 @@ import com.github.kittinunf.fuel.core.Response
import com.github.kittinunf.fuel.core.ResponseDeserializable
import com.github.kittinunf.fuel.core.response
import com.github.kittinunf.result.Result
import kotlinx.io.InputStream
import kotlinx.io.Reader
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.serializer
import java.io.InputStream
import java.io.Reader

inline fun <reified T : Any> Request.responseObject(
loader: DeserializationStrategy<T>,
json: Json = Json.plain,
json: Json = Json(JsonConfiguration.Stable),
noinline deserializer: (Request, Response, Result<T, FuelError>) -> Unit
) = response(kotlinxDeserializerOf(loader, json), deserializer)

@ImplicitReflectionSerializer
inline fun <reified T : Any> Request.responseObject(
json: Json = Json.plain,
json: Json = Json(JsonConfiguration.Stable),
noinline deserializer: (Request, Response, Result<T, FuelError>) -> Unit
) = responseObject(T::class.serializer(), json, deserializer)

inline fun <reified T : Any> Request.responseObject(
deserializer: ResponseHandler<T>,
loader: DeserializationStrategy<T>,
json: Json = Json.plain
json: Json = Json(JsonConfiguration.Stable)
) = response(kotlinxDeserializerOf(loader, json), deserializer)

@ImplicitReflectionSerializer
inline fun <reified T : Any> Request.responseObject(
deserializer: ResponseHandler<T>,
json: Json = Json.plain
json: Json = Json(JsonConfiguration.Stable)
) = responseObject(deserializer, T::class.serializer(), json)

inline fun <reified T : Any> Request.responseObject(
loader: DeserializationStrategy<T>,
json: Json = Json.plain
json: Json = Json(JsonConfiguration.Stable)
) = response(kotlinxDeserializerOf(loader, json))

@ImplicitReflectionSerializer
inline fun <reified T : Any> Request.responseObject(
json: Json = Json.plain
json: Json = Json(JsonConfiguration.Stable)
) = responseObject(T::class.serializer(), json)

inline fun <reified T : Any> kotlinxDeserializerOf(
loader: DeserializationStrategy<T>,
json: Json = Json.plain
json: Json = Json(JsonConfiguration.Stable)
) = object : ResponseDeserializable<T> {
override fun deserialize(content: String): T? = json.parse(loader, content)
override fun deserialize(reader: Reader): T? = deserialize(reader.readText())
Expand All @@ -65,5 +66,5 @@ inline fun <reified T : Any> kotlinxDeserializerOf(

@ImplicitReflectionSerializer
inline fun <reified T : Any> kotlinxDeserializerOf(
json: Json = Json.plain
) = kotlinxDeserializerOf(T::class.serializer(), json)
json: Json = Json(JsonConfiguration.Stable)
) = kotlinxDeserializerOf(T::class.serializer(), json)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.github.kittinunf.fuel.test.MockHttpTestCase
import com.github.kittinunf.result.Result
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.list
import kotlinx.serialization.builtins.list
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.CoreMatchers.isA
Expand Down

0 comments on commit 0fff191

Please sign in to comment.