aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/DataStructures.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py
index e6dfc8b..08a7d2c 100644
--- a/src/argaze/DataStructures.py
+++ b/src/argaze/DataStructures.py
@@ -8,7 +8,7 @@ __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
from typing import TypeVar, Tuple
-from dataclasses import asdict
+from inspect import getmembers
import collections
import json
import ast
@@ -30,13 +30,20 @@ TimeStampedBufferType = TypeVar('TimeStampedBuffer', bound="TimeStampedBuffer")
def as_dict(dataclass_object) -> dict:
"""
- Get dataclass object attributes values as a dictionary.
+ Get dataclass object fields's values as a dictionary.
Returns:
- values: dictionary of dataclass attributes values
+ values: dictionary of dataclass fields's values
"""
- return {key: vars(dataclass_object)[key] for key in asdict(dataclass_object).keys()}
+ # Get data class fields names
+ fields_names = []
+ for member_name, member_value in getmembers(dataclass_object):
+ if member_name == '__dataclass_fields__':
+ fields_names = member_value.keys()
+
+ # Copy fields values
+ return {name: vars(dataclass_object)[name] for name in fields_names}
class JsonEncoder(json.JSONEncoder):
"""Specific ArGaze JSON Encoder."""