Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a default serializer for kotlin.uuid.Uuid class #2730

Open
sandwwraith opened this issue Jun 27, 2024 · 5 comments
Open

Provide a default serializer for kotlin.uuid.Uuid class #2730

sandwwraith opened this issue Jun 27, 2024 · 5 comments
Assignees

Comments

@sandwwraith
Copy link
Member

Kotlin 2.0.20 is expected to have a new MPP UUID class (https://youtrack.jetbrains.com/issue/KT-31880, JetBrains/kotlin@25ea5e8). It is reasonable to provide a built-in serializer for it, like we did for kotlin.time.Duration when it was moved to stdlib.

Adding a built-in serializer requires changes in the plugin too, so they have to be made in time, preferably in the same Kotlin 2.0.20 or Kotlin 2.1

@sandwwraith sandwwraith self-assigned this Jun 27, 2024
@hfhbd
Copy link
Contributor

hfhbd commented Jun 27, 2024

How do you want to serialize it for different formats? In string formats, like JSON, properties, xml etc., it is common to use the string representation, but for binary formats, a compact binary (using the two longs directly) would be preferred than encoding the string.

@sandwwraith
Copy link
Member Author

Good question. Initially, I was planning to add only String representation, but maybe binary serializer is also required as an additional one

@sandwwraith
Copy link
Member Author

sandwwraith commented Jun 27, 2024

Apparently, there is no standardized way of storing UUIDs in protobuf (protocolbuffers/protobuf#2224, https://groups.google.com/g/protobuf/c/THxuTQKsz54). Various implementations use string, bytes, or a pair of fixed64/uint64.

For CBOR, there is tag 37 for UUID byte string (https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml), which is an accepted extension described here: https://github.com/lucas-clemente/cbor-specs/blob/master/uuid.md

So it looks like, for now, only CBOR requires additional handling.

@Chuckame
Copy link
Contributor

Chuckame commented Jul 2, 2024

On the avro binary format, the uuid is officially represented as a string as said by the spec (the default official uuid type), but is also usually serialized as a fixed of 16 bytes to save space (36 characters/bytes vs 16 bytes), so we may also want to handle a uuid differently depending on the user config.

EDIT:
Btw, this is the same for kotlin.time.Duration where the official representation is a fixed of 12 bytes

@sandwwraith
Copy link
Member Author

Well, in the case of format-specific serializers, you can always mark Duration or Uuid with @Contextual and provide a module for Avro/Cbor. If SerializersModule is empty, a default serializer will be used for e.g. Json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants