Skip to content

Instantly share code, notes, and snippets.

@addeeandra
Last active October 31, 2019 03:09
Show Gist options
  • Save addeeandra/8ff5c3a30e25d4e78039dd98bb5dd800 to your computer and use it in GitHub Desktop.
Save addeeandra/8ff5c3a30e25d4e78039dd98bb5dd800 to your computer and use it in GitHub Desktop.
Example of @TypeConverters in Room Persistence Database
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