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 None if is_my_obj and is_my_dict are 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

object_hook

default(obj: Any) Any#
object_hook(dct: Dict) Any#