From b6207eab2537471522a85ceb2e1544547e754476 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Fri, 14 Jun 2024 15:56:33 +0200 Subject: [PATCH] Fixed deserialization of enums --- src/random_events/set.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/random_events/set.py b/src/random_events/set.py index 791a220..28158d1 100644 --- a/src/random_events/set.py +++ b/src/random_events/set.py @@ -5,6 +5,7 @@ from typing_extensions import Self, TYPE_CHECKING, Dict, Any from .sigma_algebra import * +from .utils import get_full_class_name class SetElement(AbstractSimpleSet, int, enum.Enum): @@ -57,11 +58,15 @@ def __lt__(self, other): return self.value < other.value def to_json(self) -> Dict[str, Any]: - return {**super().to_json(), "value": self.value} + return {"type": get_full_class_name(SetElement), "value": self.value, + "class_name": self.__class__.__name__, "content": dict(map(lambda item: (item.name, item.value), + self.__class__)) +} @classmethod def _from_json(cls, data: Dict[str, Any]) -> Self: - return cls(data["value"]) + deserialized_class = SetElement(data["class_name"], data["content"]) + return deserialized_class(data["value"]) def as_composite_set(self) -> AbstractCompositeSet: return Set(self)