-
-
Save anhvt52/4b776adbb77e38d4c32c4f3ca46e3957 to your computer and use it in GitHub Desktop.
Android Room @TypeConverter using Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(entities = arrayOf(Note::class, User::class), version = 1) | |
@TypeConverters(Converters::class) | |
abstract class AppDatabse : RoomDatabase() { | |
abstract fun userDAO(): UserDAO | |
abstract fun noteDAO(): NoteDAO | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tinmegali.daggerwithkotlin.room | |
import android.arch.persistence.room.TypeConverter | |
import java.util.Date | |
class Converters { | |
@TypeConverter | |
fun fromTimestamp(value: Long?): Date? { | |
return if (value == null) null else Date(value) | |
} | |
@TypeConverter | |
fun dateToTimestamp(date: Date?): Long? { | |
return date?.time | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment