diff --git a/cassis/xmi.py b/cassis/xmi.py index a73b6fa..b354bab 100644 --- a/cassis/xmi.py +++ b/cassis/xmi.py @@ -437,6 +437,10 @@ def _parse_primitive_array(self, type_: Type, value: Union[str, List[str]]) -> L return [float(e) for e in elements] if value else [] elif type_name in [TYPE_NAME_INTEGER_ARRAY, TYPE_NAME_SHORT_ARRAY, TYPE_NAME_LONG_ARRAY]: return [int(e) for e in elements] if value else [] + elif type_name == TYPE_NAME_STRING_ARRAY: + if elements: + raise ValueError(f"String array values must be provided as nested elements: {elements}") + return [] elif type_name == TYPE_NAME_BOOLEAN_ARRAY: return [self._parse_bool(e) for e in elements] if value else [] elif type_name == TYPE_NAME_BYTE_ARRAY: @@ -613,10 +617,13 @@ def _serialize_feature_structure(self, cas: Cas, root: etree.Element, fs: Featur value = sofa._offset_converter.python_to_external(value) if ts.is_instance_of(feature.rangeType, TYPE_NAME_STRING_ARRAY) and not feature.multipleReferencesAllowed: - if value.elements is not None: # Compare to none to not skip if elements is empty! - for e in value.elements: - child = etree.SubElement(elem, feature_name) - child.text = e + if value.elements is not None: # Compare to none as not to skip if elements is empty! + if not value.elements: + elem.attrib[feature_name] = "" + else: + for e in value.elements: + child = etree.SubElement(elem, feature_name) + child.text = e elif ts.is_instance_of(feature.rangeType, TYPE_NAME_STRING_LIST) and not feature.multipleReferencesAllowed: if value is not None: # Compare to none to not skip if elements is empty! for e in self._collect_list_elements(feature.rangeType.name, value): diff --git a/tests/test_files/xmi/cas_with_array_features.xmi b/tests/test_files/xmi/cas_with_array_features.xmi index 3dc1fc1..6d425f7 100644 --- a/tests/test_files/xmi/cas_with_array_features.xmi +++ b/tests/test_files/xmi/cas_with_array_features.xmi @@ -1,26 +1,29 @@ - - - - - - - + + + + + + + + + blah blub - + + - - - - + + + + blah blub - +