Skip to content

Commit

Permalink
adapter.json: improve LangStringSet json serialization
Browse files Browse the repository at this point in the history
Since `LangStringSet` was changed to be an own class in
a1aaec3, we can check for a
`LangStringSet` via `isinstance()` now and simplify the JSON
serialization.
  • Loading branch information
jkhsjdhjs authored and s-heppner committed Aug 24, 2023
1 parent 539d438 commit e0e724b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions basyx/aas/adapter/json/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e0e724b

Please sign in to comment.