I have two constructors in my Kotlin object, a primary and a secondary. The primary has nothing in it and the secondary takes some parameters. I would like to map a DTO in the secondary constructor, but I don't see what is the problem.
Example
open class User(): RealmObject() {
@PrimaryKey
open var id: Long = 0
open var login: String? = null
open var firstName: String? = null
open var surname: String? = null
open var isAdmin: Boolean = false
open var groups: RealmList<Int>? = null
constructor(id: Long?, login: String?, firstName: String?, surname: String?, admin: Boolean?, groups: List<Int>?) : this()
companion object {
fun map(dto: UserDTO): User {
Timber.d(dto.toString()) //The response data from the WS, OK with some data
val groups = RealmList<Int>()
dto.groups?.forEach { groups.add(it) }
val u = User(dto.id, dto.login, dto.firstName, dto.surname, dto.admin, groups) //Calling the secondary constructor
Timber.d(u.toString()) // Everything is null or false, KO
return u
}
}
}