question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KotlinxSerializer unable to parse lists

See original GitHub issue

Ktor Version

1.1.2

Ktor Engine Used(client or server and name)

iOS Client

JVM Version, Operating System and Relevant Context

iOS 12

Feedback

Hey, the KotlinxSerializer is apparently unable to deserialized JSON payloads having lists at the root. For instance, a JSON payload like the following:

[{"foo": "bar1"}, {"foo": "bar2}]

would not be deserialized correctly.

After some trial and error, the problem lies on KotlinSerializer.kt:94:

    private fun lookupSerializerByType(type: KClass<*>): KSerializer<*> {
        mappers[type]?.let { return it } // <--
        return (type.defaultSerializer() ?: type.serializer())
    }

From what I understand, no mapper will be found because type would be kotlin.collections.List. Is that correct?

Thank you in advance 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
philmitchellcommented, Feb 25, 2019

Thanks, tried it but still got same result.

1reaction
bernatplcommented, Dec 18, 2019

Parsing lists is already working in ktor version 1.3.0 (currently beta). In this new version there is no need to register the serializers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom KotlinX Serializer for List class - Stack Overflow
This could be done without custom serializer. Just parse everything as a String (specify isLenient = true to allow unquoted strings) and ...
Read more >
Bountysource
KotlinxSerializer unable to parse lists.
Read more >
Content negotiation and serialization | Ktor
Serializing/deserializing the content in a specific format. Ktor supports the following formats out-of-the-box: JSON, XML, CBOR, and ProtoBuf.
Read more >
[Solved]-Ktor: Serialize/Deserialize JSON with List as root in ...
Now you're able to receive default collections(such a list) from the client ... serializer = KotlinxSerializer().apply { register(User.serializer().list) } ...
Read more >
Serialization | Kotlin
You can find the complete list of supported serialization formats below. All Kotlin serialization libraries belong to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found