tinmegali
7/14/2017 - 7:16 PM

Android Room @TypeConverter using Kotlin

Android Room @TypeConverter using Kotlin

@Database(entities = arrayOf(Note::class, User::class), version = 1)
@TypeConverters(Converters::class)
abstract class AppDatabse : RoomDatabase() {

    abstract fun userDAO(): UserDAO
    abstract fun noteDAO(): NoteDAO

}
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
    }

}