From 8fc4aa093eecdb87250747ccce11407be4d92904 Mon Sep 17 00:00:00 2001 From: Nikita Shevtsov Date: Thu, 28 Sep 2023 18:02:47 +0300 Subject: [PATCH] add serializable --- dedocutils/data_structures/bbox.py | 4 +++- dedocutils/data_structures/serializable.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 dedocutils/data_structures/serializable.py diff --git a/dedocutils/data_structures/bbox.py b/dedocutils/data_structures/bbox.py index bf69090..310de53 100644 --- a/dedocutils/data_structures/bbox.py +++ b/dedocutils/data_structures/bbox.py @@ -5,9 +5,11 @@ import numpy as np +from dedocutils.data_structures.serializable import Serializable + @dataclass -class BBox: +class BBox(Serializable): """ Bounding box around some page object, the coordinate system starts from top left corner. """ diff --git a/dedocutils/data_structures/serializable.py b/dedocutils/data_structures/serializable.py new file mode 100644 index 0000000..61e17f1 --- /dev/null +++ b/dedocutils/data_structures/serializable.py @@ -0,0 +1,16 @@ +from abc import ABC, abstractmethod + + +class Serializable(ABC): + """ + Base class for the serializable objects which we need convert to dict. + """ + @abstractmethod + def to_dict(self) -> dict: + """ + Convert class data into dictionary representation. + Dictionary key should be string and dictionary value should be json serializable. + + :return: dict with all class data. + """ + pass \ No newline at end of file