https://kotlinlang.org logo
#android
Title
# android
g

gsala

04/15/2019, 1:47 PM
Has anyone tried to use inline classes in a Room entity? I'm trying this:
Copy code
@Entity
data class DailySummary(
        @PrimaryKey val date: LocalDate,
        val activeTime: Duration,
        val calories: KCal // <- inline class wrapping a Float
)
and it doesn't work even if I provide a
@TypeConverter
for it. The error coming from Gradle is very meaningless so i won't post it here but changing the entity above to use
Float
instead of
KCal
automatically works. The Type Converters are these:
Copy code
@TypeConverter
    fun toKCal(value: Float?): KCal? {
        return value?.let { KCal(it) }
    }

    @TypeConverter
    fun fromKCal(kcal: KCal?): Float? {
        return kcal?.value
    }
g

gsala

04/15/2019, 3:05 PM
Ok... Star and wait I guess. Thanks 👍
r

rkeazor

04/15/2019, 3:07 PM
Arent inline classes still experimental? probably when they reach a more stable version, support for it will be available . it probably wouldn't make sense for them to add support now, when they api itself is subject to change in the future
g

gsala

04/15/2019, 3:09 PM
I guess that's true. I really hoped it would at least work providing the
TypeConverter
for it
4 Views