Skip to content

Commit

Permalink
Fix submodelElements loss after calling $metamodel endpoint (#95)
Browse files Browse the repository at this point in the history
* Fix submodelElements loss after calling $metamodel endpoint

See issue #85
  • Loading branch information
mhrimaz authored Oct 4, 2023
1 parent b6b0ee5 commit c4242c8
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
Expand Down Expand Up @@ -220,8 +224,16 @@ public SubmodelValueOnly getSubmodelByIdValueOnly(String submodelId) {
@Override
public Submodel getSubmodelByIdMetadata(String submodelId) {
Submodel submodel = getSubmodel(submodelId);
submodel.setSubmodelElements(null);
return submodel;
try {
String submodelAsJSON = new JsonSerializer().write(submodel);
Submodel submodelDeepCopy = new JsonDeserializer().readReferable(submodelAsJSON, Submodel.class);
submodelDeepCopy.setSubmodelElements(null);
return submodelDeepCopy;
} catch (DeserializationException e) {
throw new RuntimeException("Unable to deserialize the Submodel", e);
} catch (SerializationException e) {
throw new RuntimeException("Unable to serialize the Submodel", e);
}
}

@Override
Expand Down

0 comments on commit c4242c8

Please sign in to comment.