Deserialize a list of generics inside a data class with kotlinx.serialization
See original GitHub issueSay you have:
@Serializable
data class PagedData<T>(val data: T, val page: Int, val totalPages: Int, val pageSize: Int)
Where you know for sure that T
is a class that has the annotations @Serializable
or a list of a type that is annotated with @Serializable
.
Why the serialization runtime is not able to infer what to use? It would be kind of pointless to explicitly build a serializer before every response as such.
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Deserialize a list of generics inside a data class #795 - GitHub
Where you know for sure that T is a class that has the annotations @Serializable or a list of a type that is...
Read more >Deserialize a list of generics inside a data class with kotlinx ...
Deserialize a list of generics inside a data class with kotlinx.serialization ; Project, Ktor ; Type, Feature F ; Subsystem, Server ; Affected...
Read more >Deserialize generic object using Kotlin Serialization
Save this question. Show activity on this post. I am trying to replace Gson library by kotlin serialization to handle JSON serialization/ ...
Read more >Android Data Serialization Tutorial with the Kotlin Serialization ...
It's generic type parameter specifies the type of object serialized by the serializer. Open BoredActivity.kt in data. Below BoredActivity , add ...
Read more >How do i serialize a generic sealed class with kotlinx ...
For the sake of simplicity in the example I only represent the exception message. @Serializable(with = ServiceResultSerializer::class) sealed class ...
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
Hi, @lamba92. I reproduced the problem on the server, it will be fixed in the next minor release.
Don’t know if this is new or not but with a combination of Plugin generated generic serializer with Serializers module this is possible.
With these changes on your response in ktor you no longer need to serialize the object in
call.response()
method to aString