Skip to content

Commit

Permalink
Fixed deserialization of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsch420 committed Jun 14, 2024
1 parent 1d5c72c commit b6207ea
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/random_events/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b6207ea

Please sign in to comment.