CLOVIS
12/28/2025, 4:08 PMObjectId , Uuid , Timestamp etc as primitive types. However, KSerializer doesn't have the equivalent .encodeObjectId , .decodeObjectId etc methods.
I want users to be able to write custom serializers that take advantage of these primitive types. Also, these serializers should still work with other formats (with an appropriate fallback, for example ObjectId can be represented as an hex-encoded string in JSON).ephemient
12/29/2025, 4:43 AMsealed so the obvious way of doing it isn't possibleephemient
12/29/2025, 4:44 AMephemient
12/29/2025, 5:15 AMkotlin.uuid.Uuid to work by default though, you might have to special case if (serializer.descriptor == Uuid.serializer().descriptor) in your format's `encodeSerializableValue`/`decodeSerializableValue`CLOVIS
12/29/2025, 8:02 AMyou might have to special caseThat"s what I'm doing at the moment, but I have no idea if that's a good practice or not.
CLOVIS
12/29/2025, 8:03 AMuse an existing kind and an annotation to mark your extended primitive types insteadIs there documentation on how to do that?
efemoney
12/29/2025, 9:02 AMIs there documentation on how to do that?Mark a custom annotation with
@SerialInfo, that means that when your users put that custom annotation on a class / property, then the annotation will be added to the annotations property of the descriptor as metadata that you can use while serializing or deserializingAdam S
12/29/2025, 9:37 AM> you might have to special case
That"s what I'm doing at the moment, but I have no idea if that's a good practice or not.I think that's expected. The 'Efficient binary format' example handles ByteArrays specially, by checking if
serializer.descriptor == byteArraySerializer.descriptor.
https://github.com/Kotlin/kotlinx.serialization/blob/v1.9.0/docs/formats.md#format-specific-types