Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix submodelElements loss after calling $metamodel endpoint #95

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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