Last active
October 31, 2019 03:09
-
-
Save addeeandra/8ff5c3a30e25d4e78039dd98bb5dd800 to your computer and use it in GitHub Desktop.
Example of @TypeConverters in Room Persistence Database
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
import androidx.room.TypeConverters | |
import java.util.* | |
class FieldConverters { | |
@TypeConverters | |
fun fromTimestamp(value: Long?): Date? { | |
return value?.let { Date(it) } | |
} | |
@TypeConverters | |
fun toTimestamp(date: Date?): Long? { | |
return date?.time | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment