KotlinxSerializer unable to parse lists
See original GitHub issueKtor 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:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top 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 >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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, tried it but still got same result.
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.