Skip to content

serializer_i.py

ofrak.service.serialization.serializers.serializer_i

SerializerInterface

targets: Tuple[Union[Type, Callable[[Type], bool]], ...] property readonly

Mandatory attribute telling the dependency injector which types this serializer is responsible for.

Targets can be types, or predicates of a type hint returning whether the serializer handles this type.

obj_to_pjson(self, obj, type_hint)

Serialize the object to PJSON. Note that the generic self._service.to_pjson can be used here.

Source code in ofrak/service/serialization/serializers/serializer_i.py
@abstractmethod
def obj_to_pjson(self, obj: Any, type_hint: Any) -> PJSONType:
    """Serialize the object to PJSON. Note that the generic `self._service.to_pjson` can be used here."""
    raise NotImplementedError()

pjson_to_obj(self, pjson_obj, type_hint)

Deserialize PJSON into the object. Note that the generic self._service.from_pjson can be used here.

Source code in ofrak/service/serialization/serializers/serializer_i.py
@abstractmethod
def pjson_to_obj(self, pjson_obj: Any, type_hint: Any) -> Any:
    """Deserialize PJSON into the object. Note that the generic `self._service.from_pjson` can be used here."""
    raise NotImplementedError()