Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore kotlin delegated property using Room ```@Ignore``` annotation

I want to add a delegated property to my Composition class, as follows

@Entity
data class Composition(
        val author: String="",
        val background: String?,
        val description: String="",
        val downloadURL: String="",
        val duration: String="",
        val headPortrait: String?,
        @PrimaryKey val id: String,
        val isLike: Boolean,
        val likeAmount: String="",
        val playingAmount: Int=0,
        val replyAmount: String?,
        val showStyle: String?,
        val title: String?,
        val userId: String?,
        val commentAmount: String?,
        val cover: String=""
){

    val  showDuration by lazy{
        val minutes = duration.toInt() /60
        val seconds =duration.toInt()%60
        "$minutes:$seconds"
    }
}

But there gona be a compile error because delegated property can not be saved in database. So i want to add an Ignore annotation to this field. What a pity that Androidstuio will throws a complain "This annotation is not applicable to target 'member property with delegate" . Who has ideas for this problem?

like image 969
Cyrus Avatar asked May 29 '20 07:05

Cyrus


1 Answers

As user IR42 points out in his comment, you can use @delegate:Ignore.

like image 99
Mikael Ohlson Avatar answered Jan 28 '23 16:01

Mikael Ohlson