any_serializer.py
ofrak.service.serialization.serializers.any_serializer
AnySerializer (SerializerInterface)
Serialize and deserialize objects with type hint Any
into PJSONType
.
Implementation: a simple and conservative design in which the object is only serialized
if it's already of PJSONType
(the check is performed by beartype and the method signatures).
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/any_serializer.py
def obj_to_pjson(self, obj: PJSONType, _type_hint: Any) -> PJSONType:
return obj
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/any_serializer.py
def pjson_to_obj(self, pjson_obj: PJSONType, _type_hint: Any) -> PJSONType:
return pjson_obj