Deserialize a list of generics inside a data class
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? Also, I am using Ktor, it would be kind of pointless to explicitly build a serializer before every response as such.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (6 by maintainers)
Top Results From Across the Web
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 >java - Jackson - Deserialize using generic class - Stack Overflow
The problem is that "Data" is a generic class. I need to specify what type T is at runtime. The parameter clazz is...
Read more >Serializing and Deserializing a List with Gson - Baeldung
In this tutorial, we'll explore a few advanced serialization and deserialization cases for List using Google's Gson library.
Read more >How to deserialize a JSON array to list generic type in Java?
How to deserialize a JSON array to list generic type in Java? - The Gson library provides a class called com.google.gson.reflect.
Read more >Deserialize a generic object that contains a generic object-kotlin
the method that instantiates the DataSourceManager class, I have two generic types, "List < String>" is the parameter type of the webservice query, ......
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
Please never use Gson.
– Signed, a Gson mainterner.
Answered on stackoverflow. Basically kotlinx.serialization normally resolves type statically, the ktor respond function is reified inline to hide this, but may lead to surprising behaviour for the unaware.