From e0e724bac4532c6b7a8826a8c74b059340edf33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Tue, 22 Aug 2023 19:34:50 +0200 Subject: [PATCH] adapter.json: improve `LangStringSet` json serialization Since `LangStringSet` was changed to be an own class in a1aaec350c172cb5d17a6917087be7c4a8b076ec, we can check for a `LangStringSet` via `isinstance()` now and simplify the JSON serialization. --- basyx/aas/adapter/json/json_serialization.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/basyx/aas/adapter/json/json_serialization.py b/basyx/aas/adapter/json/json_serialization.py index 704917995..3a057de0e 100644 --- a/basyx/aas/adapter/json/json_serialization.py +++ b/basyx/aas/adapter/json/json_serialization.py @@ -77,6 +77,7 @@ def default(self, obj: object) -> object: model.Extension: self._extension_to_json, model.File: self._file_to_json, model.Key: self._key_to_json, + model.LangStringSet: self._lang_string_set_to_json, model.MultiLanguageProperty: self._multi_language_property_to_json, model.Operation: self._operation_to_json, model.OperationVariable: self._operation_variable_to_json, @@ -123,11 +124,11 @@ def _abstract_classes_to_json(cls, obj: object) -> Dict[str, object]: if obj.id_short: data['idShort'] = obj.id_short if obj.display_name: - data['displayName'] = cls._lang_string_set_to_json(obj.display_name) + data['displayName'] = obj.display_name if obj.category: data['category'] = obj.category if obj.description: - data['description'] = cls._lang_string_set_to_json(obj.description) + data['description'] = obj.description try: ref_type = next(iter(t for t in inspect.getmro(type(obj)) if t in model.KEY_TYPES_CLASSES)) except StopIteration as e: @@ -341,14 +342,14 @@ def _data_specification_iec61360_to_json( """ data_spec: Dict[str, object] = { 'modelType': 'DataSpecificationIEC61360', - 'preferredName': cls._lang_string_set_to_json(obj.preferred_name) + 'preferredName': obj.preferred_name } if obj.data_type is not None: data_spec['dataType'] = _generic.IEC61360_DATA_TYPES[obj.data_type] if obj.definition is not None: - data_spec['definition'] = cls._lang_string_set_to_json(obj.definition) + data_spec['definition'] = obj.definition if obj.short_name is not None: - data_spec['shortName'] = cls._lang_string_set_to_json(obj.short_name) + data_spec['shortName'] = obj.short_name if obj.unit is not None: data_spec['unit'] = obj.unit if obj.unit_id is not None: @@ -379,7 +380,7 @@ def _data_specification_physical_unit_to_json( 'modelType': 'DataSpecificationPhysicalUnit', 'unitName': obj.unit_name, 'unitSymbol': obj.unit_symbol, - 'definition': cls._lang_string_set_to_json(obj.definition) + 'definition': obj.definition } if obj.si_notation is not None: data_spec['siNotation'] = obj.si_notation @@ -474,7 +475,7 @@ def _multi_language_property_to_json(cls, obj: model.MultiLanguageProperty) -> D """ data = cls._abstract_classes_to_json(obj) if obj.value: - data['value'] = cls._lang_string_set_to_json(obj.value) + data['value'] = obj.value if obj.value_id: data['valueId'] = obj.value_id return data