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.

Deserialize a list of generics inside a data class

See original GitHub issue

Say 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
JakeWhartoncommented, Apr 10, 2020

Please never use Gson.

  – Signed, a Gson mainterner.

0reactions
pdvriezecommented, Dec 5, 2021

I got the similar problem today: https://stackoverflow.com/q/70207677/3466808, any one can help?

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.

Read more comments on GitHub >

github_iconTop 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 >

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