eclipse-aaspe / package-explorer

AASX Package Explorer
Other
64 stars 19 forks source link

[BUG] The import/export of JSON in PE is not working when using JSON serialization/deserialization with the basyx-python-sdk. #254

Open JS-Aibel opened 1 month ago

JS-Aibel commented 1 month ago

Describe the bug When using the methods in the basyx-python-sdk to serialize a submodel to a JSON file, the file can not be imported in the Package Explorer with the use of Import Submodel from JSON.

To Reproduce By using the basyx-python-sdk do the following.

  1. Create a submodel
  2. Serialize the submodel to a JSON file
  3. Code to reproduce:
    
    #!/usr/bin/env python3
    from basyx.aas import model
    import basyx.aas.adapter.json

identifier = 'https://acplt.org/Simple_Submodel' submodel = model.Submodel(id_=identifier)

obj_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore() obj_store.add(submodel)

with open('data.json', "w") as file: basyx.aas.adapter.json.write_aas_json_file(file, obj_store)


4. Open an AAS with the Package Explorer
5. In Package Explorer go to` File -> Import -> Import Submodel from JSON `and select the JSON file
6. Error message in Package Explorer occurs: **Submodel Read: No valid Submodel, Env, source file selected**
7. An error still occurs after trying the workaround in [Import Submodel as JSON · Issue #30 · eclipse-aaspe/package-explorer (github.com)](https://github.com/eclipse-aaspe/package-explorer/issues/30)
**Error: Submodel Read: Can not read SubModel.: Unexpected property**

**Expected behavior**
Import/export in PE should work with the sdk's serialization/deserialization.

**Additional context**
Deserialization of a file from Package Explorer `Export Submodel from JSON` into basyx-python-sdk does not work either.
StenGruener commented 1 month ago

+1

JS-Aibel commented 1 month ago

It seems like the sdk serialization starts with a key ‘submodels’, which is an array of submodels. While the Package Explorer is serializing as a submodel key/value pair, except for it missing the attribute modelType, it looks like an element in the submodels array from the serialization.

I guess the question is whether the SDK or the Package Explorer needs to be changed to improve their interoperability?

juileetikekar commented 1 month ago

Hi @JS-Aibel,

Could you please share the JSON file that can be used to reproduce this issue at AASPE end?

JS-Aibel commented 1 month ago

Thank you for the reply, @juileetikekar.

JSON form basyx-python-sdk

{
    "submodels": [
        {
            "modelType": "Submodel",
            "id": "https://acplt.org/Simple_Submodel"
        }
    ]
}

By removing the submodels array, leaving only the single element, Package Explorer is able to import the submodel. Could it be possible that when Package Explorer encounters a "submodels" array, it should import each element within that array?

Modified Version of JSON with ‘Submodels’ Array Removed

{
    "modelType": "Submodel",
    "id": "https://acplt.org/Simple_Submodel"
}