I’m not sure I’m following that. It’s not possible...
# squarelibraries
c
I’m not sure I’m following that. It’s not possible to define a
ColumnAdapter<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:
Copy code
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.
Copy code
class Adapter(
    val sentDateAdapter: ColumnAdapter<SentDate, String>
  )
I’ve tried defining the column two separate ways but the generated adapter is the same:
Copy code
sentDate TEXT AS SentDate DEFAULT NULL
sentDate TEXT AS SentDate