I am fetching a JSON object which contains a generic member (data can be of a few different types). The class currently looks like this:
@Parcelize
data class Children<T: Parcelable>(
@Json(name = "type") val type: String,
@Json(name = "data") val data: T
): Parcelable
How do I go about being able to deserialize/map the correct object type with moshi?
@Parcelize
data class Comment<T : Parcelable>(
@Json(name = "replies") val replies: Children<T>,
@Json(name = "count") val count: Int,
@Json(name = "children") val childs: List<String>
) : Parcelable
Or how about instances such as this? I should note Comment can take a generic param of Comment thus resulting in a loop.
from How to deserialize generic class members with moshi?
No comments:
Post a Comment