Skip to main content

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

AttributeTypeDescription
default_tagslistThis 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

NameTypeDescription
tag_classtype[[JSONTag](jsontag.md?sid=flask_json_tag_jsontag)]tag class to register. Will be instantiated with this serializer instance.
forcebool = Falseoverwrite an existing tag. If false (default), a KeyError is raised.
index`intNone` = None

Returns

TypeDescription
None

tag()

@classmethod
def tag(
value: t.Any
) - > t.Any

Convert a value to a tagged representation if necessary.

Parameters

NameTypeDescription
valuet.AnyThe value to convert to a tagged representation.

Returns

TypeDescription
t.Any

untag()

@classmethod
def untag(
value: dict[str, t.Any]
) - > t.Any

Convert a tagged representation back to the original type.

Parameters

NameTypeDescription
valuedict[str, t.Any]The dictionary representing a tagged value to convert back to its original type.

Returns

TypeDescription
t.Any

dumps()

@classmethod
def dumps(
value: t.Any
) - > str

Tag the value and dump it to a compact JSON string.

Parameters

NameTypeDescription
valuet.AnyThe value to be tagged and serialized into a JSON string.

Returns

TypeDescription
str

loads()

@classmethod
def loads(
value: str
) - > t.Any

Load data from a JSON string and deserialized any tagged objects.

Parameters

NameTypeDescription
valuestrThe JSON string to load and deserialize, potentially containing tagged objects.

Returns

TypeDescription
t.Any