I have a data class below. Using coroutines and converting results as UserItem objects with gson.
The problem is, in the init block the object is still uninitialized and the nick, images etc. variables are empty. Where should I write the code in the init block?
data class UserItem(
@SerializedName("username") val nick: String = "",
@SerializedName("full_name") val fullName: String = 0,
@SerializedName("info") val bio: String = "",
@SerializedName("images") val images: List<String> =
arrayListOf(),
var imageType: ImageType = ImageType.NO_PHOTO
){
companion object {
@JvmStatic
val DISPLAY_TYPE_USER = 0
@JvmStatic
val DISPLAY_TYPE_INFO = 1
}
enum class ImageType {
NO_PHOTO, SINGLE_PHOTO, MULTIPLE_PHOTO
}
init {
if (images.size == 1)
imageType = ImageType.SINGLE_PHOTO
else if (images.size > 1)
imageType = ImageType.MULTIPLE_PHOTO
}
}