# getting-started


10/09/2017, 5:37 PM
I try to make an extensible User class, this class will be save as JSON and will be updated by JSON
Copy code
data class User(val firstName: String?,
           val lastName: String?,
           val gender: UserGender?,
           val type: UserType?,
           val picture: String?,
           val locale: String?,
           val heart: Int?,
           val level: Int?,
           val timezone: String?
) : JsonObject() {

    init {
        put(, firstName ?: this[])
        put(, lastName ?: this[])
        put(, gender ?: this[])
        put(, type ?: this[])
        put(, picture ?: this[])
        put(, locale ?: this[])
        put(, heart ?: this[])
        put(, level ?: this[])
        put(, timezone ?: this[])

fun User.update(userUpdate: JsonObject) {
    userUpdate.fieldNames().forEach({ fieldName ->
        this.put(fieldName, userUpdate.getValue(fieldName))
Using this, I can Update the class and add dynamically a property cars on my User class by doing:
Copy code
And I can continue to use user.firstName instead of user.get(“firstName”) What do you thing about this way to do?