hello) . Need some help.I know how to transfer data from A class to B class, but i dont know how to transfer data from subclass A.A1 - which included A class, to subclass B.B1 which included B class.
My A class:
data class SpaceXProperty(
val flight_number: Int,
val launch_year: Int,
val links: Links
){
data class Links(val mission_patch: String?)
}
My B class:
data class Models(val flightNumber: Int,
val mlinks: Mlinks
)
{
data class Mlinks(val mission_patch: String?)
}
I created next function
fun List<SpaceXProperty>.asDomainModel(): List<Models>{
return map {
Models(
flightNumber = it.flight_number,
llinks = it.links //here i got error type mismatch "required: Models.Mlinks found: SpaceXProperty.Links"
)
}
}
So thats to avoid this - i change B class to next
data class Models(val flightNumber: Int,
val llinks: SpaceXProperty.Links
)
I new at kotlin, so dont know how correctly mapping data from one subclass to another. Help please.
i trying to put next function at fun List.asDomainModel(), but its dont work.
fun List<SpaceXProperty.Links>.asDDomainmodel(): List<Models.Llinks>{
return map {
Models.Llinks(
mission_patch = it.mission_patch) }
}
Totally i getting data from "https://api.spacexdata.com/v3/launches" and want paste this data to another data class like "repository". Here Moshi cannot parse nullable i get help that i need to use subclass, but at next step i got problems.