Android – kotlin: sugar ORM insists @ ignoring attributes

In my Android application, I used kotlin with sugarorm. I encountered a problem trying to prevent some properties from being persisted. Ironically, when used in kotlin class, the @ com.orm.dsl.ignore annotation seems to be ignored

for instance,

1) Let's announce two seemingly identical models:

// JavaUser.java
public class JavaUser extends SugarRecord {
    public String login = "login";
    @Ignore public String password = "password";
}

// KotlinUser.kt
class KotlinUser : SugarRecord() {
    var login: String = "login"
    @Ignore var password: String = "password"
}

2) Stick to their examples

JavaUser().save()
KotlinUser().save()

3) And see what actually exists:

sqlite> select * from java_user;
ID|LOGIN
1|login

sqlite> select * from kotlin_user;
ID|LOGIN|PASSWORD
1|login|password

I realize that it may have something to do with kotlin annotation processing, but I'm just not sure how to do it. Any suggestion is the most popular

resolvent:

The core difference between Java and kotlin code is that fields are used in Java, but properties are used in kotlin. Please refer to the properties and fields section in the document

You can try the following solutions to see how sugarorm works:

1. Let kotlin reveal areas:

@Ignore @JvmField var password: String = "password"

2. Apply comments to private support fields:

@field:Ignore var password: String = "password"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>