Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛[Bug] [Extension] Fix KotlinX serialization problem #733

Merged
merged 2 commits into from
Apr 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
@@ -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"
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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())
@@ -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
@@ -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