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
| Attribute | Type | Description |
|---|---|---|
| key | str | This 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The value to be checked for 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. This method is used to serialize a UUID for JSON output.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The UUID object to be converted. |
Returns
| Type | Description |
|---|---|
t.Any | The 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The hexadecimal string representing a UUID. |
Returns
| Type | Description |
|---|---|
t.Any | A UUID object created from the input string. |