Ofir Bar
03/04/2020, 12:50 PMAdvertisement
which contains a few enums.
@Parcelize
data class Advertisement(
@SerializedName("type") val type : AdvertisementType,
@SerializedName("userTypeTarget") val userTypeTarget : UserTypeTarget,
@SerializedName("goal") val advertisementGoal : AdvertisementGoal,
@SerializedName("attachTo") val attachTo : AttachTo,
) : Parcelable
enum class AdvertisementType(private val value : Int) {
REGULAR(0),
SOS(1)
}
enum class AttachTo(private val value : Int){
ME(0),
MY_OFFICE(1)
}
enum class UserTypeTarget(private val value : Int){
LAWYER(0),
SERVICE_PROVIDER(1)
}
enum class AdvertisementGoal(private val value : Int){
COLLABORATION(0),
CASE_TRANSFER(1),
COURT_TRANSFER(2),
FORM_VALIDATION(3)
}
As you can see, my object properties are enums.
However, our backend only accepts Integers.
I need to make all the properties into Integers, but I don’t want any future developer to ever create an instance of`Advertisement` directly with some Int, and use the created enums instead.
How can I force the insertion of enums yet the actual value of created `Advertisement`to be an Int?satyan
03/04/2020, 1:07 PMRestAdvertisement
which can be mapped from/to an Advertisement
Ofir Bar
03/04/2020, 2:28 PMsatyan
03/04/2020, 2:30 PMOfir Bar
03/04/2020, 3:12 PMval type : AdvertisementType
get() = type.toInt() // pseudo code, but I wonder if such thing possible
This way I set enum but get Int I guess.
Is there a possible wrong thing with that approach I might havn’t think of?