UUIDSerializer

object UUIDSerializer : KSerializer<UUID>

A custom Kotlinx Serialization serializer for Mojang-style UUID strings.

Mojang's APIs use a compact UUID format (32 hexadecimal characters without hyphens). This serializer ensures UUIDs are encoded in that format and decoded back into standard Java UUID objects.

Also provides a helper method to convert compact or hyphenated UUID strings into valid UUID instances.

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Describes this serializer as a primitive string type, since UUIDs are encoded and decoded using their string form.

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): UUID

Decodes a compact or hyphenated UUID string into a UUID.

Link copied to clipboard
open override fun serialize(encoder: Encoder, value: UUID)

Encodes a UUID into Mojang's compact (no-hyphen) 32-character format.

Link copied to clipboard
fun stringToUUID(uuidString: String): UUID

Converts a compact (no-hyphen) or hyphenated UUID string into a standard Java UUID by inserting hyphens at the correct positions.