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 |
|---|---|---|
| tags | dict[str, [JSONTag](jsontag.md?sid=src_flask_json_tag_jsontag)] | A mapping of unique string keys to their corresponding JSONTag instances used for looking up deserialization logic. |
| order | list[[JSONTag](jsontag.md?sid=src_flask_json_tag_jsontag)] | An ordered list of JSONTag instances used to determine the sequence in which values are checked for tagging during serialization. |
| default_tags | list[type[[JSONTag](jsontag.md?sid=src_flask_json_tag_jsontag)]] = [TagDict, PassDict, TagTuple, PassList, TagBytes, TagMarkup, TagUUID, TagDateTime] | Tag classes to bind when creating the serializer. Other tags can be added later using :meth:~register. |
Constructor
Signature
def TaggedJSONSerializer() - > None
Methods
register()
@classmethod
def register(
tag_class: type[[JSONTag](jsontag.md?sid=src_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=src_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 Python object to be checked and potentially converted into a tagged format. |
Returns
| Type | Description |
|---|---|
t.Any | The tagged representation of the value, or the original value if no tag matches. |
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] | A dictionary potentially containing a single key representing a registered tag. |
Returns
| Type | Description |
|---|---|
t.Any | The reconstructed Python object if a valid tag key is found, otherwise the original dictionary. |
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 Python object to be tagged and serialized into JSON. |
Returns
| Type | Description |
|---|---|
str | A compact JSON string representation of the tagged value. |
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 be parsed and untagged. |
Returns
| Type | Description |
|---|---|
t.Any | The original Python object, including reconstructed complex types. |