diff --git a/sdk/basyx/aas/adapter/json/json_serialization.py b/sdk/basyx/aas/adapter/json/json_serialization.py index 8f21fe91..4f03ce71 100644 --- a/sdk/basyx/aas/adapter/json/json_serialization.py +++ b/sdk/basyx/aas/adapter/json/json_serialization.py @@ -1,4 +1,4 @@ -# Copyright (c) 2025 the Eclipse BaSyx Authors +# Copyright (c) 2026 the Eclipse BaSyx Authors # # This program and the accompanying materials are made available under the terms of the MIT License, available in # the LICENSE file of this project. @@ -476,7 +476,8 @@ def _blob_to_json(cls, obj: model.Blob) -> Dict[str, object]: :return: dict with the serialized attributes of this object """ data = cls._abstract_classes_to_json(obj) - data['contentType'] = obj.content_type + if obj.content_type is not None: + data['contentType'] = obj.content_type if obj.value is not None: data['value'] = base64.b64encode(obj.value).decode() return data @@ -490,7 +491,8 @@ def _file_to_json(cls, obj: model.File) -> Dict[str, object]: :return: dict with the serialized attributes of this object """ data = cls._abstract_classes_to_json(obj) - data['contentType'] = obj.content_type + if obj.content_type is not None: + data['contentType'] = obj.content_type if obj.value is not None: data['value'] = obj.value return data diff --git a/sdk/basyx/aas/adapter/xml/xml_serialization.py b/sdk/basyx/aas/adapter/xml/xml_serialization.py index 0607a064..c309ee1d 100644 --- a/sdk/basyx/aas/adapter/xml/xml_serialization.py +++ b/sdk/basyx/aas/adapter/xml/xml_serialization.py @@ -1,4 +1,4 @@ -# Copyright (c) 2025 the Eclipse BaSyx Authors +# Copyright (c) 2026 the Eclipse BaSyx Authors # # This program and the accompanying materials are made available under the terms of the MIT License, available in # the LICENSE file of this project. @@ -627,7 +627,8 @@ def blob_to_xml(obj: model.Blob, if obj.value is not None: et_value.text = base64.b64encode(obj.value).decode() et_blob.append(et_value) - et_blob.append(_generate_element(NS_AAS + "contentType", text=obj.content_type)) + if obj.content_type is not None: + et_blob.append(_generate_element(NS_AAS + "contentType", text=obj.content_type)) return et_blob @@ -643,7 +644,8 @@ def file_to_xml(obj: model.File, et_file = abstract_classes_to_xml(tag, obj) if obj.value: et_file.append(_generate_element(NS_AAS + "value", text=obj.value)) - et_file.append(_generate_element(NS_AAS + "contentType", text=obj.content_type)) + if obj.content_type is not None: + et_file.append(_generate_element(NS_AAS + "contentType", text=obj.content_type)) return et_file diff --git a/sdk/basyx/aas/model/submodel.py b/sdk/basyx/aas/model/submodel.py index 6ce0d22e..7fbc3eea 100644 --- a/sdk/basyx/aas/model/submodel.py +++ b/sdk/basyx/aas/model/submodel.py @@ -474,7 +474,7 @@ class Blob(DataElement): def __init__(self, id_short: Optional[base.NameType], - content_type: base.ContentType, + content_type: Optional[base.ContentType] = None, value: Optional[base.BlobType] = None, display_name: Optional[base.MultiLanguageNameType] = None, category: Optional[base.NameType] = None, @@ -492,7 +492,7 @@ def __init__(self, super().__init__(id_short, display_name, category, description, parent, semantic_id, qualifier, extension, supplemental_semantic_id, embedded_data_specifications) self.value: Optional[base.BlobType] = value - self.content_type: base.ContentType = content_type + self.content_type: Optional[base.ContentType] = content_type @_string_constraints.constrain_content_type("content_type") @@ -528,7 +528,7 @@ class File(DataElement): def __init__(self, id_short: Optional[base.NameType], - content_type: base.ContentType, + content_type: Optional[base.ContentType] = None, value: Optional[base.PathType] = None, display_name: Optional[base.MultiLanguageNameType] = None, category: Optional[base.NameType] = None, @@ -546,7 +546,7 @@ def __init__(self, super().__init__(id_short, display_name, category, description, parent, semantic_id, qualifier, extension, supplemental_semantic_id, embedded_data_specifications) self.value: Optional[base.PathType] = value - self.content_type: base.ContentType = content_type + self.content_type: Optional[base.ContentType] = content_type class ReferenceElement(DataElement):