serialization#

Functions

check_object(obj)

default(o)

Customized JSON serializer.

deserialize(data)

Deserialize the JSON string back to an object.

serialize(obj)

Serialize the object to a json string.

to_dict(obj)

Convert the object to a dictionary.

Classes

ObjectTypes(value[, names, module, ...])

class ObjectTypes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

CLASS = 1#
INSTANCE = 2#
TYPE = 3#
check_object(obj) ObjectTypes[source]#
default(o: Any) Dict[str, Any] | str[source]#

Customized JSON serializer.

  1. Support internal dataclasses and components instance serialization by calling to_dict() method.

  2. Support internal dataclasses class serialization by calling to_dict_class() method.

  3. Any external instance if it has to_dict() method, it will be serialized.

  4. All other objects will be serialized as {“type”: type(o).__name__, “data”: str(o)}

serialize(obj: Mapping[str, Any]) str[source]#

Serialize the object to a json string.

Parameters:

obj (Mapping[str, Any]) – The object to be serialized.

Returns:

The serialized object in json format.

Return type:

str

deserialize(data: str) Any[source]#

Deserialize the JSON string back to an object.

to_dict(obj: Any) Dict[str, Any][source]#

Convert the object to a dictionary.

Parameters:

obj (Any) – The object to be converted.

Returns:

The dictionary representation of the object.

Return type:

Dict[str, Any]