TypeConverter



Marks a function as a type converter. A class can have as many @TypeConverter functions as it needs.

Converter functions are useful for helping Room support types beyond the built-in ones, primitives String, ByteArray and enums. @TypeConverter functions are for converting a column values may it be when reading from a query result or binding parameters into a statement.

Each converter function should receive 1 parameter and have non-void / non-Unit return type.

// Example converter for Date
object Converters {
@TypeConverter
fun fromTimestamp(value: Long?): Date? {
return value == null ? null : Date(value)
}

@TypeConverter
fun dateToTimestamp(date: Date?): Long? {
if (date == null) {
return null
} else {
return date.getTime()
}
}
}
See also
TypeConverters

Summary

Public constructors

Cmn

Public constructors

TypeConverter

TypeConverter()