Home > Enterprise >  How can I Parcelize data class contain list from another data class? in Kotlin
How can I Parcelize data class contain list from another data class? in Kotlin

Time:01-22

I try to Parcelize this data class but the problem is contain a list from another data class

@Parcelize
data class Data(
    val alternative_titles: List<String>,
    val authors: List<String> = emptyList(),
    val chapters: List<Chapter> = emptyList(),
    val description: String ="",
    val genres: List<String> = emptyList(),
    val last_updated: String ="",
    val rating: Double =0.0,
    val rating_count: Int= 0,
    val status: String ="",
    val title: String ="",
    val views_count: String =""
): Parcelable

The error in line chapters:
enter image description here

and the other data class

data class Chapter(
    val id: String,
    val number: Int,
    val title: String,
    val uploaded_at: String,
    val url: String,
    val views_count: Int
)

CodePudding user response:

just add the @Parcelize and Parcelable also to the other data class. so like

@Parcelize
data class Chapter(
    val id: String,
    val number: Int,
    val title: String,
    val uploaded_at: String,
    val url: String,
    val views_count: Int
): Parcelable
  •  Tags:  
  • Related