TagUUID
This class provides a mechanism for serializing and deserializing UUID objects to and from JSON. It identifies UUID instances, converts them to their hexadecimal string representation for storage, and reconstructs the original UUID objects during decoding.
Attributes
| Attribute | Type | Description |
|---|---|---|
| key | string = u | The unique tag identifier used during JSON serialization to distinguish UUID types. |
Methods
check()
@classmethod
def check(
value: t.Any
) - > bool
Checks if the provided value is an instance of a UUID object.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to be validated against the UUID type |
Returns
| Type | Description |
|---|---|
bool | True 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 for JSON serialization.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The UUID instance to be serialized |
Returns
| Type | Description |
|---|---|
t.Any | A string containing the 32-character hexadecimal representation of the UUID |
to_python()
@classmethod
def to_python(
value: t.Any
) - > t.Any
Parses a hexadecimal string and reconstructs the corresponding UUID object.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The serialized value, typically a hexadecimal string, to be converted back into a UUID object |
Returns
| Type | Description |
|---|---|
t.Any | A new UUID instance initialized from the provided input value |