Skip to content

Instantly share code, notes, and snippets.

@NikolayKul
Created May 4, 2018 13:32
Show Gist options
  • Save NikolayKul/3a091ba50e6f10d3f396ef53aeaf7c74 to your computer and use it in GitHub Desktop.
Save NikolayKul/3a091ba50e6f10d3f396ef53aeaf7c74 to your computer and use it in GitHub Desktop.
Android Room @TypeConverter example in Kotlin
/*
Singleton that contains all `@TypeConverter`s of the app.
Mark all inner converters with `@JvmStatic` so Room can use them as regular static functions
*/
object Converters {
@TypeConverter
@JvmStatic
fun convertDateFrom(value: Date?): Long? = value?.time
@TypeConverter
@JvmStatic
fun convertDateTo(value: Long?): Date? = value?.let(::Date)
}
@Database(entities = [DummyEntity::class], version = 1)
@TypeConverters(Converters::class)
abstract class DummyDatabase : RoomDatabase() {
abstract fun dummyDao(): DummyDao
}
@dimaslanjaka
Copy link

where dao class ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment