Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin and @Transient

hava a class:

open class MessageDTO : RealmObject, Serializable {

    @PrimaryKey
    @SerializedName("message_id")
    var messageId: String? = null

    @SerializedName("chat")
    var chat: String? = null

    @SerializedName("chat_type")
    var chatType: String? = null

    @SerializedName("content")
    var content: ContentDTO? = null

    @SerializedName("created")
    var created: Date? = null

    @SerializedName("from")
    var from: String? = null

    @SerializedName("important")
    var important: Boolean? = null

    @SerializedName("is_first")
    var isFirst: Boolean? = null

    @SerializedName("is_group")
    var isGroup: Boolean? = null

    @SerializedName("is_last")
    var isLast: Boolean? = null

    @SerializedName("linked_messages")
    var linkedMessages: RealmList<MessageDTO>? = null

    @SerializedName("links")
    var links: RealmList<ModelLinks>? = null

    @SerializedName("read")
    var read: Boolean? = null

    @SerializedName("to")
    var to: String? = null

    @Ignore
    var displayName: String? = null

    @Ignore
    var authorPhoto: ModelIcons? = null

    @Transient
    var deliveredToServer: Boolean = false

and need to use @Transient with variable deliveredToServer but have compile error:

e: error: Class "MessageDTO" contains illegal transient field "deliveredToServer". e:

e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing

what could be the problem?

like image 973
no news Avatar asked Nov 03 '17 08:11

no news


People also ask

What is transient in Kotlin?

<init> Marks the JVM backing field of the annotated property as transient , meaning that it is not part of the default serialized form of the object.

What does transient mean in java?

Transient in Java is used to indicate that a field should not be part of the serialization process. The modifier Transient can be applied to member variables of a class to turn off serialization on these member variables. Every field that is marked as transient will not be serialized.


1 Answers

Transient fields were not supported in 3.1.3 and had to be explicitly ignored with @Ignore.

See the change log.

3.2.0 (2017-05-16)

Transient fields are now allowed in model classes, but are implicitly treated as having the @Ignore annotation (#4279).

like image 186
EpicPandaForce Avatar answered Nov 03 '22 02:11

EpicPandaForce