I'm new to Kotlin, I encountered the problem as follow. The structure of the data class is a bit complicated.
I need to write a function in data class offerSystem to build the whole MyContent class.
My question is I want to pass value of language in Offer and title in OfferDescription to language and title in ContentItem respectively, but I do not know how.
data class OfferSystem(
val id: String,
val offers: List<Offer>
)
data class Offer(
val offerType: String,
val offerDescription: List<OfferDescription>,
val language: Locale
)
data class OfferDescription(
val title: String,
val content: String
)
I want to set value for one of the variables(contents) in a data class MyContent. The contents itself is a list of ContentItem, which has several variables.
data class MyContent( // there are other val here
val contents: List<ContentItem>
)
data class ContentItem(
val title: String,
val language: Locale,
)
I tried
data class OfferSystem(
val id: String,
val offers: List<Offer>
){
fun toMyContent(): MyContent {
return MyContent(
...
contents = listOf(ContentItem(title = ???, language = ???))
...
)
}
}
I have no idea how to extract language and title