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

kotlinx-serialization with List<T> throws #844

Open
MihaMarkic opened this issue Nov 22, 2022 · 1 comment
Open

kotlinx-serialization with List<T> throws #844

MihaMarkic opened this issue Nov 22, 2022 · 1 comment

Comments

@MihaMarkic
Copy link

Bug Report

Description

Can't make kotlinx-serialization to decode a list of objects from a JSON string. If I use responseString and 'manually' decode from the resulting string, it works.

To Reproduce

Steps to reproduce the behavior:

Below are two blocks of code, first doesn't work, second does.

@Serializable
data class Store(val storeID: String)

   // does not work
    val (request, response, data) = Fuel.get(address)
        .awaitObjectResponse<List<Store>>(
            kotlinxDeserializerOf()
        )
  // does work
  val httpAsync = Fuel.get(address)
        .responseString { request, response, result ->
            result.fold({ d ->
                    val obj = json.decodeFromString<List<Store>>(d)
                    println(obj[0].name)
            }, { e ->
                println(e.message)
            })
        }

Expected behavior

Should deserialize string.

Actual behavior

Throws the exception below.
Exception stack:

Exception in thread "main" Expected class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available) as the serialized body of kotlinx.serialization.Polymorphic<List>, but had class kotlinx.serialization.json.JsonArray (Kotlin reflection is not available)
	com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:86)
	com.github.kittinunf.fuel.core.DeserializableKt.awaitResponse(Deserializable.kt:258)
Caused by: kotlinx.serialization.json.internal.JsonDecodingException: Expected class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available) as the serialized body of kotlinx.serialization.Polymorphic<List>, but had class kotlinx.serialization.json.JsonArray (Kotlin reflection is not available)
	kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
	kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:94)
	kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:81)
	kotlinx.serialization.json.Json.decodeFromString(Json.kt:95)
	MainKt$test$$inlined$kotlinxDeserializerOf$1.deserialize(FuelSerialization.kt:55)

Environment

IntelliJ IDEA Community

@JellyBrick
Copy link

#817 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants