polymerist.genutils.fileutils.jsonio.serialize ============================================== .. py:module:: polymerist.genutils.fileutils.jsonio.serialize .. autoapi-nested-parse:: Interfaces for extending what types of objects can be serialized to JSON Attributes ---------- .. autoapisummary:: polymerist.genutils.fileutils.jsonio.serialize.T polymerist.genutils.fileutils.jsonio.serialize.JSONSerializable Classes ------- .. autoapisummary:: polymerist.genutils.fileutils.jsonio.serialize.TypeSerializer polymerist.genutils.fileutils.jsonio.serialize.MultiTypeSerializer polymerist.genutils.fileutils.jsonio.serialize.PathSerializer polymerist.genutils.fileutils.jsonio.serialize.QuantitySerializer polymerist.genutils.fileutils.jsonio.serialize.NDArraySerializer Functions --------- .. autoapisummary:: polymerist.genutils.fileutils.jsonio.serialize.enum_serializer_factory Module Contents --------------- .. py:data:: T .. py:data:: JSONSerializable .. py:class:: TypeSerializer Bases: :py:obj:`abc.ABC` Interface for defining how types which are not JSON serializable by default should be encoded and decoded .. py:attribute:: python_type :type: ClassVar[Type[T]] .. py:method:: encode(python_obj: T) -> JSONSerializable :staticmethod: :abstractmethod: .. py:method:: decode(json_obj: JSONSerializable) -> T :staticmethod: :abstractmethod: .. py:method:: encoder_default(python_obj: Any) -> JSONSerializable :classmethod: Augmented Encoder for encoding registered objects along with type info for decoding .. py:method:: decoder_hook(json_dict: dict[JSONSerializable, JSONSerializable]) -> Union[dict, T] :classmethod: .. py:class:: MultiTypeSerializer(*type_sers: tuple[Type[TypeSerializer]]) For dynamically merging multiple TypeSerializer encoders and decoders .. py:property:: type_sers :type: list[Type[TypeSerializer]] Read-only wrapper for the internal registry of TypeSerializers .. py:method:: add_type_serializer(obj: Union[TypeSerializer, MultiTypeSerializer]) -> None For type, instance, and uniqueness checking of Type .. py:method:: encoder_default(python_obj: Any) -> JSONSerializable .. py:method:: decoder_hook(json_dict: dict[JSONSerializable, JSONSerializable]) -> Any .. py:class:: PathSerializer Bases: :py:obj:`TypeSerializer` For JSON-serializing OpenMM Quantities .. py:method:: encode(python_obj: pathlib.Path) -> str :staticmethod: Stringify path object .. py:method:: decode(json_obj: str) -> pathlib.Path :staticmethod: Resolve string into system Path .. py:class:: QuantitySerializer Bases: :py:obj:`TypeSerializer` For JSON-serializing OpenMM Quantities .. py:method:: encode(python_obj: openmm.unit.Quantity) -> dict[str, Union[str, float]] :staticmethod: Separate openmm.unit.Quantity's value and units to serialize as a single dict .. py:method:: decode(json_obj: dict[str, Union[str, float]]) -> openmm.unit.Quantity :staticmethod: Unpack a value-unit string dict back into a usable openmm.unit.Quantity .. py:class:: NDArraySerializer Bases: :py:obj:`TypeSerializer` For JSON-serializing of numpy n-dimensional arrays .. py:method:: encode(python_obj: numpy.ndarray[Any]) -> list[Any] :staticmethod: List-ify array and store string descriptor of numpy dtype .. py:method:: decode(value: list[Any]) -> numpy.ndarray[Any] :staticmethod: Reassemble numpy array from list and dtype .. py:function:: enum_serializer_factory(enumtype: enum.EnumType) -> TypeSerializer Factory for generating a TypeSerializer specific to an Enum type