I have two distinct classes:
internal data class ClassB(
@Json(name = "id") val id: String?,
@Json(name = "name") val name: String?,
@Json(name = "url") var contentUrl: String?,
@Json(name = "mediaImageUri") val coverUrl: String?,
@Json(name = "mediaVideoCoverImageUri") val videoCoverUrl: String?
)
internal data class ClassC(
@Json(name = "tileId") val id: String?,
@Json(name = "friendId") val friendId: String?,
@Json(name = "profilePictureUri") var profilePicture: String?,
@Json(name = "name") var name: String?
)
That inherit from the same class:
internal open class ClassA(
@Json(name ="type") var type: String?,
@Json(name ="sponsor-offer") var offer: SponsorOffer?,
@Json(name ="date") var date: Date?,
@Json(name ="weight") var priorityWeight: Int?
)
I am using an API call that returns a list of ClassA and is parsed by retrofit into a List, and need to cast each object onto one of the child classes before adding it to a local ArrayList<Any>
I am attempting to do this by iterating through the list returned and checking for the proprietary attributes of Classes B and C. then casting to object to the appropriate one before adding it to a local array. How can I check for these attributes? Is there a better way to do what I am attempting to do?
classA.javaClass.kotlin.members.any
is not working