JSONCodec#
- class gufe.custom_json.JSONCodec(cls: type | None, to_dict: Callable[[Any], dict], from_dict: Callable[[dict], Any], is_my_obj: Callable[[Any], bool] | None = None, is_my_dict=None)#
Custom JSON encoding and decoding for non-default types.
- Parameters:
cls (class) – Class for this codec. Assumes that all subclasses should be treated the same way. Can be
Noneifis_my_objandis_my_dictare given.to_dict (Callable) – method that converts the object to a dictionary
from_dict (Callable) – method that restores the object based on the dictionary made by to_dict
is_my_obj (Optional[Callable]) – Method to determine whether the input object should be treated by this encoder. Default behavior is to use
isinstance(cls), and to create a dict that also includes the class name and the module of the object.is_my_dict (Optional[Callable]) – Method to determine whether the input dictionary should be treated by this decoder. Default behavior assumes usage of the default
is_my_obj.
Methods
- default(obj: Any) Any#
- object_hook(dct: dict) Any#