TaggedJSONSerializer
Serializer that uses a tag system to compactly represent objects that are not JSON types. Passed as the intermediate serializer to :class:itsdangerous.Serializer.
Attributes
| Attribute | Type | Description |
|---|---|---|
| default_tags | list | This attribute specifies the list of tag classes to bind when the serializer is created, allowing for the initial setup of supported non-JSON types. |
Constructor
Signature
def TaggedJSONSerializer() - > None
Methods
register()
@classmethod
def register(
tag_class: type[[JSONTag](jsontag.md?sid=flask_json_tag_jsontag)],
force: bool = False,
index: int | None = None
) - > None
Register a new tag with this serializer.
Parameters
| Name | Type | Description |
|---|---|---|
| tag_class | type[[JSONTag](jsontag.md?sid=flask_json_tag_jsontag)] | tag class to register. Will be instantiated with this serializer instance. |
| force | bool = False | overwrite an existing tag. If false (default), a KeyError is raised. |
| index | `int | None` = None |
Returns
| Type | Description |
|---|---|
None |
tag()
@classmethod
def tag(
value: t.Any
) - > t.Any
Convert a value to a tagged representation if necessary.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The value to convert to a tagged representation. |
Returns
| Type | Description |
|---|---|
t.Any |
untag()
@classmethod
def untag(
value: dict[str, t.Any]
) - > t.Any
Convert a tagged representation back to the original type.
Parameters
| Name | Type | Description |
|---|---|---|
| value | dict[str, t.Any] | The dictionary representing a tagged value to convert back to its original type. |
Returns
| Type | Description |
|---|---|
t.Any |
dumps()
@classmethod
def dumps(
value: t.Any
) - > str
Tag the value and dump it to a compact JSON string.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The value to be tagged and serialized into a JSON string. |
Returns
| Type | Description |
|---|---|
str |
loads()
@classmethod
def loads(
value: str
) - > t.Any
Load data from a JSON string and deserialized any tagged objects.
Parameters
| Name | Type | Description |
|---|---|---|
| value | str | The JSON string to load and deserialize, potentially containing tagged objects. |
Returns
| Type | Description |
|---|---|
t.Any |