Skip to main content

TagUUID

This class handles the serialization and deserialization of UUID objects to and from JSON. It checks if a value is a UUID instance, converts UUIDs to their hexadecimal string representation for JSON, and reconstructs UUID objects from hexadecimal strings.

Attributes

AttributeTypeDescription
keystrThis attribute stores the string key used to identify the UUID tag within a JSON structure.

Methods


check()

@classmethod
def check(
value: t.Any
) - > bool

Checks if the provided value is an instance of UUID. This method is used to validate if a given object is a UUID type.

Parameters

NameTypeDescription
valuet.AnyThe value to be checked for UUID type.

Returns

TypeDescription
boolTrue if the value is a UUID instance, False otherwise.

to_json()

@classmethod
def to_json(
value: t.Any
) - > t.Any

Converts a UUID object into its hexadecimal string representation. This method is used to serialize a UUID for JSON output.

Parameters

NameTypeDescription
valuet.AnyThe UUID object to be converted.

Returns

TypeDescription
t.AnyThe hexadecimal string representation of the UUID.

to_python()

@classmethod
def to_python(
value: t.Any
) - > t.Any

Converts a hexadecimal string into a UUID object. This method is used to deserialize a UUID from a JSON input.

Parameters

NameTypeDescription
valuet.AnyThe hexadecimal string representing a UUID.

Returns

TypeDescription
t.AnyA UUID object created from the input string.