-
Notifications
You must be signed in to change notification settings - Fork 668
Description
What is your use-case and why do you need this feature?
The uuid representation is often format specific. Json/StringFormats often uses the hexString representation, while binary formats like CBOR or Protobuf use a format specific representation, not a common one.
Currently, it is not possible to encode/decode a uuid value in a format specific representation per format as a format author.
It is only possible to use a custom format specific serializer if the user annotated the usage of kotlin.uui.Uuid with @Contextual and provided a custom serializer via SerializerModule.
Describe the solution you'd like
In Encoder/CompositeEncoder/Decoder/CompositeDecoder add encode/decodeUuid, with a default implementation that uses the Uuid.serializer() as fallback.
This allows other formats to override the method to implement a format specific uuid encoder/decoder.
interface Encoder {
fun encodeUuid(value: Uuid) { UuidSerializer.serialize(this, value) }
}
interface Decoder {
fun decodeUuid(): Uuid = UuidSerializer.deserialize(decoder = this)
}Related:
#2730
hfhbd/kotlinx-uuid#422