All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.c0x12c.featureflag.serializer.UuidSerializer.kt Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
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
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy