model.ZoneIdBSONCodec.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baku Show documentation
Show all versions of baku Show documentation
helps you focus your REST API back-end on the business logic
package com.github.fluidsonic.baku
import org.bson.BsonReader
import org.bson.BsonWriter
import java.time.ZoneId
internal object ZoneIdBSONCodec : AbstractBSONCodec(includesSubclasses = true) {
override fun BsonReader.decode(context: BSONCodingContext) =
readString().let { id ->
ZoneId.of(id) ?: error("invalid timezone: $id")
}
override fun BsonWriter.encode(value: ZoneId, context: BSONCodingContext) {
writeString(value.id)
}
}