class DtoSerializationHandler(object): def __init__(self, registry: Registry): self.deserializer = Deserializer(registry) self.serializer = Serializer() def deserialize(self, object, type): return self.deserializer.deserialize(object, type) def serialize(self, obj): return self.serializer.serialize(obj)
class ObjectMapper(object): def __init__(self): self.deserializer = Deserializer(ObjectMapper.__RegistryStub()) self.serializer = Serializer() def deserialize(self, json_str: str, clazz: Type[T]) -> T: dictionary = json.loads(json_str) return self.deserializer.deserialize(dictionary, clazz) def serialize(self, serializable: object) -> str: dictionary = self.serializer.serialize(serializable) return json.dumps(dictionary) class __RegistryStub(Registry): @Override def is_annotated(self, object: object, annotation: "Annotation"): return annotation == Serializable and object not in BUILTIN_TYPES + (dict,)