Hey I'm using one model as DTO, JsonCreator and Percelize my problem is that i want to use polymorphism (disassemble common part) and have no idea how to write it in Kotlin.
@Parcelize
@Entity
open class Location (var lat: Double = 0.0, var lng: Double = 0.0) :Parcelable
@Parcelize
@Entity
class MapsMarker(lat: Double, lng: Double, var name: String): Location(lat, lng), Parcelable
An issue here is that compiles shouts
Parcelizable constructor parameter should be "var or val"
for fields lat
, lng
of MapsMarker
.
I'm using inheritance so I can't use val because I will override properties of the Location
class. I also dont want my room @Entity will have duplicated fields.
If anyone knows the answer please help me ;)
@Parcelize does not work well with inheritance issue link. You can still have custom parceler like mentioned here
<<<< not related to your question but consider giving a shot >>>>
Your MapsMarker class is violating is a
relationship -> MapsMarker is a Location?
It should not inherit from Location instead prefer composition -> MapsMarker has a
Location
@Parcelize
@Entity
class MapsMarker(val location: Location, var name: String): Parcelable
You can find many blogs detailing class designs. This is the first related google result I got now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With