eclipse-basyx / basyx-java-sdk

java-sdk
MIT License
26 stars 33 forks source link

json serialization for `AssetAdmistrationShells` does not return `Asset` as referable #65

Closed the-nic closed 2 years ago

the-nic commented 2 years ago

I have the following example assets in xml formal:

<?xml version="1.0"?>
<aas:aasenv xmlns:IEC="http://www.admin-shell.io/IEC61360/2/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:abac="http://www.admin-shell.io/aas/abac/2/0" xsi:schemaLocation="http://www.admin-shell.io/aas/2/0 AAS.xsd http://www.admin-shell.io/IEC61360/2/0 IEC61360.xsd" xmlns:aas="http://www.admin-shell.io/aas/2/0">
  <aas:assetAdministrationShells>
    <aas:assetAdministrationShell>
      <aas:idShort>CA_AAS</aas:idShort>
      <aas:identification idType="IRI">1220_8141_0112_0875</aas:identification>
      <aas:derivedFrom>
        <aas:keys>
          <aas:key type="AssetAdministrationShell" local="true" idType="IdShort">6455_1111_0112_4769</aas:key>
        </aas:keys>
      </aas:derivedFrom>
      <aas:assetRef>
        <aas:keys>
          <aas:key type="Asset" local="true" idType="IRI">1030_8141_0112_5510</aas:key>
        </aas:keys>
      </aas:assetRef>
      <aas:submodelRefs />
      <aas:conceptDictionaries />
    </aas:assetAdministrationShell>
  </aas:assetAdministrationShells>
  <aas:assets>
    <aas:asset>
      <aas:idShort>CA</aas:idShort>
      <aas:identification idType="IRI">1030_8141_0112_5510</aas:identification>
      <aas:kind>Instance</aas:kind>
    </aas:asset>
  </aas:assets>
  <aas:submodels />
  <aas:conceptDescriptions />
</aas:aasenv>

and a call to endpoint /shells returns

[
    {
        "conceptDictionary": [],
        "assetRef": {
            "keys": [
                {
                    "idType": "IRI",
                    "type": "Asset",
                    "value": "1030_8141_0112_5510",
                    "local": true
                }
            ]
        },
        "identification": {
            "idType": "IRI",
            "id": "1220_8141_0112_0875"
        },
        "idShort": "CA_AAS",
        "dataSpecification": [],
        "derivedFrom": {
            "keys": [
                {
                    "idType": "IdShort",
                    "type": "AssetAdministrationShell",
                    "value": "6455_1111_0112_4769",
                    "local": true
                }
            ]
        },
        "modelType": {
            "name": "AssetAdministrationShell"
        },
        "asset": {
            "identification": {
                "idType": "IRI",
                "id": "1030_8141_0112_5510"
            },
            "idShort": "CA",
            "kind": "Instance",
            "dataSpecification": [],
            "modelType": {
                "name": "Asset"
            },
            "embeddedDataSpecifications": []
        },
        "embeddedDataSpecifications": [],
        "views": [],
        "submodels": []
    }
]

However, the fields in asset must be Referables, ie.

    "asset": {
        "keys": [
            {
                "type": "Asset",
                "idType": "IRI",
                "value": "1030_8141_0112_5510",
                "local": true
            }
        ]
    }

See also https://github.com/eclipse-basyx/basyx-python-sdk/issues/9#issuecomment-1074420174

FrankSchnicke commented 2 years ago

Many thanks for pointing this out. We're discussing internally how to address this issue.

Due to compatibility issues, there's no easy and clean fix. However, we could combine the required information with the already existing information, i.e.:

"asset": {
    "keys": [
        {
            "type": "Asset",
            "idType": "IRI",
            "value": "1030_8141_0112_5510",
            "local": true
        }
    ],
   "identification": {
            "idType": "IRI",
            "id": "1030_8141_0112_5510"
    },
"idShort": "CA",
"kind": "Instance",
"dataSpecification": [],
"modelType": {
    "name": "Asset"
},
"embeddedDataSpecifications": []
}

Would this work for you?

the-nic commented 2 years ago

since i am using basyx-python-sdk, I guess so, yes. As a workaround I rewrote the payload to use assetRef.

FrankSchnicke commented 2 years ago

Fixed and will be included in next release. Again, many thanks for pointing this out!