TagDict
Tag for 1-item dicts whose only key matches a registered tag.
Attributes
| Attribute | Type | Description |
|---|---|---|
| key | string = " di" | The unique identifier used by the serializer to represent a 1-item dictionary tag in JSON output. |
Methods
check()
@classmethod
def check(
value: t.Any
) - > bool
Determines if a value is a single-item dictionary whose key corresponds to a registered tag in the serializer.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to evaluate for compatibility with this tag type |
Returns
| Type | Description |
|---|---|
bool | True if the value is a dictionary of length one with a valid tag key, False otherwise |
to_json()
@classmethod
def to_json(
value: t.Any
) - > t.Any
Converts a single-item dictionary into its JSON-safe representation by appending a double-underscore suffix to the key and recursively tagging the value.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The single-item dictionary to be serialized |
Returns
| Type | Description |
|---|---|
t.Any | A dictionary with the suffixed key and the serialized version of the original value |
to_python()
@classmethod
def to_python(
value: t.Any
) - > t.Any
Restores a JSON-serialized dictionary back to its Python form by removing the double-underscore suffix from the dictionary key.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The serialized dictionary containing a suffixed key |
Returns
| Type | Description |
|---|---|
t.Any | A dictionary containing the original key name and the associated value |