Created
February 17, 2021 03:42
-
-
Save jobinlawrance/0061e103646c70e85a4937a603dcd46b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TimeStampSurrogateSerializer : KSerializer<Timestamp> { | |
override val descriptor: SerialDescriptor = TimestampSurrogate.serializer().descriptor | |
override fun serialize(encoder: Encoder, value: Timestamp) { | |
val surrogate = TimestampSurrogate(value.date.getAsTime()) | |
encoder.encodeSerializableValue(TimestampSurrogate.serializer(), surrogate) | |
} | |
override fun deserialize(decoder: Decoder): Timestamp { | |
val surrogate = decoder.decodeSerializableValue(TimestampSurrogate.serializer()) | |
return Timestamp(Date(surrogate.timeInMillis)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment