com.c0x12c.featureflag.serializer.UuidSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
A module for managing feature flags
package com.c0x12c.featureflag.serializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.util.UUID
class UuidSerializer : KSerializer {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING)
override fun serialize(
encoder: Encoder,
value: UUID
) {
encoder.encodeString(value.toString()) // Serialize UUID as a string
}
override fun deserialize(decoder: Decoder): UUID {
return UUID.fromString(decoder.decodeString()) // Deserialize string back into UUID
}
}