Skip to content

Commit

Permalink
Fix submodelElements loss after calling $metamodel endpoint
Browse files Browse the repository at this point in the history
See issue #85
  • Loading branch information
mhrimaz committed Oct 2, 2023
1 parent b6b0ee5 commit bea93ab
Showing 1 changed file with 16 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,18 @@ 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) {
e.printStackTrace();
throw new RuntimeException("Unable to deserialize the Submodel");
} catch (SerializationException e) {
e.printStackTrace();
throw new RuntimeException("Unable to serialize the Submodel");
}
}

@Override
Expand Down

0 comments on commit bea93ab

Please sign in to comment.