Kotlin: @ Ignores properties stored by Sugar ORM

In my Android app, I use Kotlin with SugarORM and I ran into a problem trying to prevent some properties from being saved. Oddly enough, the annotation is @com.orm.dsl.Ignoreapparently ignored when used in Kotlin classes.

As an example,

1) let them 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) keep their instances

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

3) and see what actually persists:

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

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

I understand that this may be due to the processing of the Kotlin annotation, but I'm just not sure how I can do this. Any suggestions are welcome.

+4
source share
1 answer

Java Kotlin , Java , Kotlin . . .

, SugarORM:

1. Kotlin :

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

2. :

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

Source: https://habr.com/ru/post/1659279/


All Articles