UnreadCounts.kt 989 Bytes
Newer Older
Christophe Henry's avatar
Christophe Henry committed
1
package fr.chenry.android.freshrss.store.api.models
2

3 4 5 6 7 8
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.datatype.joda.deser.LocalDateTimeDeserializer
import org.joda.time.DateTimeZone
import org.joda.time.LocalDateTime
9 10 11 12 13 14

data class UnreadCountsHandler(val max: Int, val unreadcounts: List<UnreadCount>)

data class UnreadCount(
    val id: String,
    val count: Int,
15 16
    @JsonDeserialize(using = MicroSecTimestampDeserializer::class)
    val newestItemTimestampUsec: LocalDateTime
17 18
)

19 20 21 22 23
class MicroSecTimestampDeserializer: LocalDateTimeDeserializer() {
    override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): LocalDateTime {
        val tz = if(_format.isTimezoneExplicit) _format.timeZone else DateTimeZone.forTimeZone(ctxt?.timeZone)
        return LocalDateTime(p?.valueAsString?.toLongOrNull()?.div(1000), tz)
    }
24
}