Hey, I’ve got two data classes like so: ``` data c...
# announcements
a
Hey, I’ve got two data classes like so:
Copy code
data class FleetUnitJson(
    val id: Int,
    val stock_no: String,
    val children: List<FleetUnitJson>
)

data class FleetUnit(
    val id: Int,
    val stock_no: String
)
How can I create a FleetUnit from a FleetUnitJson? I can pass all the properties to the constructor of course but I thought there might be an easier way.
a
You could add
fun toFleetUnit() = FleetUnit(id, stock_no)
to FleetUnitJson
a
Thanks @arve that’s pretty much what I’ve ended up doing. There were just loads of properties so it felt a bit unwieldy, but Android Studio made it simple actually.
g
I would rather use extension function than member function to have less coupling between classes
👍 1