What is the proper way to deserialize a List of things?
See original GitHub issueI’ve a data class and a request which returns a list of these objects. What is the proper way to deserialize the list? I don’t want to write an explicit deserializer just for List<CommitStatus>
I tried to do automatic deserialization with .httpGet().responseObject<List<CommitStatus>> { ... }
It returns a list of things nicely, but then it fails when accessing the list elements.
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to io.smartly.balex.receiver.CommitStatus
This is my data class:
data class CommitStatus(val state: String, val context: String, val target_url: String) {
class Deserializer : ResponseDeserializable<CommitStatus> {
override fun deserialize(content: String): CommitStatus? {
return Gson().fromJson(content, CommitStatus::class.java)
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Deserialize list of objects in C# - Stack Overflow
You need to deserialize your List object. You can try using Generics: public List<T> Deserialize<T>(string path) { return JsonConvert.
Read more >C# - Deserialize JSON to List of Employee Objects - YouTube
In this episode, I show you how to deserialize JSON string into a list of Employee objects and display them on the console...
Read more >How to Serialize Deserialize List of Objects in Java ... - Crunchify
Here is a complete example. These are the steps: · Create Class Item() which implements Serializable. · In Main – Create 2 Item...
Read more >Serializing and Deserializing a List with Gson - Baeldung
One way to solve this is to add type information to the serialized JSON. We honor that type information during JSON deserialization. For...
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
@deiga Thanks for reporting this.
Hmm I think I used
Fuel
to work with List of items before. Can we do something like this?Usage
Let me know if it doesn’t.
If this is useful, I think we can add this into the README.md so people can refer it as an example 😉
This is fixed properly with 2.0.0