Cody Engel
12/19/2019, 3:47 PMColumnAdapter<OffsetDateTime?, String?>
because the interface is defined as: ColumnAdapter<T : kotlin.Any, S>
. So when I try to work around that by creating a class hierarchy that encapsulates null as so:
sealed class SentDate {
object NotSent : SentDate()
data class Sent(val at: OffsetDateTime): SentDate()
}
object SentDateColumnAdapter : ColumnAdapter<SentDate, String?> {
override fun decode(databaseValue: String?): SentDate {
return when (databaseValue) {
null -> SentDate.NotSent
else -> SentDate.Sent(at = OffsetDateTime.parse(databaseValue))
}
}
override fun encode(value: SentDate): String? {
return when (value) {
is SentDate.NotSent -> null
is SentDate.Sent -> value.at.toString()
}
}
}
I am still unable to do that because the generated Adapter generates an expected ColumnAdapter
where the String
is not null.
class Adapter(
val sentDateAdapter: ColumnAdapter<SentDate, String>
)
I’ve tried defining the column two separate ways but the generated adapter is the same:
sentDate TEXT AS SentDate DEFAULT NULL
sentDate TEXT AS SentDate