47degrees / memeid

RFC-compliant Universally Unique Identifiers (UUID) for the JVM
Apache License 2.0
57 stars 7 forks source link

Kotlin wrapper for the Java library #92

Open purrgrammer opened 4 years ago

purrgrammer commented 4 years ago

Like memeid-scala, which wraps our UUID type with an idiomatic API for the language.

ahinchman1 commented 4 years ago

It'd be really nice to add compatibility kotlin extensions for serialization. It currently doesn't exist for UUIDs but could be acheived using a small wrapper class. Something like:

@Serializer(forClass = UUID::class)
    object UUIDSerializer : KSerializer<UUID> {
        override val descriptor: SerialDescriptor
            get() = StringDescriptor.withName("UUID")

        override fun serialize(output: Encoder, obj: UUID) {
            output.encodeString(obj.toString())
        }

        override fun deserialize(input: Decoder): UUID {
            return UUID.fromString(input.decode())
        }
    }

References: