Error: Contains illegal final field -Kotlin

Viewed 3796

I am using a Kotlin data class with Realm, Gson annotation for fetching Data from server.

Problem: When i run project in android studio it gives following error

Error:Class "VenderConfig" contains illegal final field "name".

I am learning Kotlin so don't have much idea about that.

My VenderConfig class is:

@RealmClass
class VenderConfig(
        @SerializedName("name")
        val name: String? = null,
        @SerializedName("website")
        val wb_url: String? = null,
        @SerializedName("icon")
        val icon: String? = null,
        @SerializedName("logo")
        val logo: String? = null,
        @SerializedName("description")
        val description: String? = null,
        @PrimaryKey
        @SerializedName("id")
        val id: Int? = null
) : RealmObject() {

}

I have also tried open keyword with the field and remove data keyword also, but it did not solve the issue.

2 Answers

Shouldn't the class be open? (me-too ;)

@Realm-database: realm-java-3.1.0.zip \examples\kotlinExample\src\main\kotlin\io\realm\examples\kotlin\model\Person.kt

    package io.realm.examples.kotlin.model

    import io.realm.RealmList
    import io.realm.RealmObject
    import io.realm.annotations.Ignore
    import io.realm.annotations.PrimaryKey

    // ... 
    // Furthermore, the class and all of the properties
    // must be annotated with open 
    // (Kotlin classes and methods are final by default).
    // 
    open class Person(

    ...

    ) : RealmObject() {
        // The Kotlin compiler generates standard getters and setters.
        // Realm will overload them and code inside them is ignored.
        // So if you prefer you can also just have empty abstract methods.
    }
Related