Skip to content

Add Unixseconds serializer #181

Open
@hfhbd

Description

@hfhbd

Many APIs return a unix timestamp, the seconds from the epoch as Long.
Although the serializer is easy to create, it could be provided.

public object InstantUnixSecondsSerializer : KSerializer<Instant> {
    override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Instant", PrimitiveKind.LONG)

    override fun deserialize(decoder: Decoder): Instant = Instant.fromEpochSeconds(decoder.decodeLong())

    override fun serialize(encoder: Encoder, value: Instant) {
        encoder.encodeLong(value.epochSeconds)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    formattersRelated to parsing and formatting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions