-
Notifications
You must be signed in to change notification settings - Fork 2
Correct serialization so that reserialize Library works #25
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
Conversation
@@ -152,7 +152,7 @@ public static Metamodel getInstance() { | |||
namespacedEntity.addFeature(Property.createRequired("qualifiedName", LionCoreBuiltins.getString(), | |||
"LIonCore_M3_NamespacedEntity_qualifiedName").setDerived(true)); | |||
|
|||
namespaceProvider.addFeature(Property.createRequired("namespaceQualifier", LionCoreBuiltins.getString(), "LIonCore_M3_NamespaceProvider_namespaceQualifier")); | |||
namespaceProvider.addFeature(Property.createRequired("namespaceQualifier", LionCoreBuiltins.getString(), "LIonCore_M3_NamespaceProvider_namespaceQualifier").setDerived(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now aligned to the TS implementation
@@ -100,7 +101,7 @@ private JsonObject serializeThisNode(Node node) { | |||
jsonObject.addProperty(ID_LABEL, node.getID()); | |||
|
|||
JsonObject properties = new JsonObject(); | |||
node.getConcept().allProperties().forEach(property -> { | |||
node.getConcept().allProperties().stream().filter(p -> !p.isDerived()).forEach(property -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not serialize the derived features now.
I think we should actually serialize derived features, as the receiving part could not have the logic to calculate the values, so it is beneficial to send the derived value. I will disk this with @dslmeinte during the next meeting on serialization
@@ -16,13 +16,23 @@ | |||
"nNUEzZ7it7d2HoHPAtk5rGO4SsqVA3hAlBwkK1KP8QU", | |||
"RDa_L8gbU8XgW9z46oMysBi1Hb7vjcS8O8LUgXlFpeU" | |||
] | |||
} | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the JSON file always to include all the keys (containment, references, parent, etc.) based on LionWeb-io/specification#59. I assumed the same logic applied also to parent
"parent": "OcDK2GESljInG-ApIqtkXUoA2UeviB97u0UuiZzM0Hs" | ||
}, | ||
{ | ||
"concept": "LIonCore_M3_Concept", | ||
"id": "Pk1NRJfHMt4eSja2kpXia7x8vj6Vzc6WQCUzT3aVeYY", | ||
"properties": { | ||
"LIonCore_M3_NamespacedEntity_simpleName": "Library", | ||
"LIonCore_M3_Concept_abstract": false | ||
"LIonCore_M3_Concept_abstract": "false" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made sure that all property values are strings (see LionWeb-io/lionweb-typescript#38)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now _un_aligned with the TS-implementation, but we'll discuss this on Wednesday as well.
I'm unsure about the experimental parts. They are not supported in the current MPS implementation, let's see if that breaks something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some questions/comments/suggestions, but don't have to be processed in this PR, necessarily.
"parent": "OcDK2GESljInG-ApIqtkXUoA2UeviB97u0UuiZzM0Hs" | ||
}, | ||
{ | ||
"concept": "LIonCore_M3_Concept", | ||
"id": "Pk1NRJfHMt4eSja2kpXia7x8vj6Vzc6WQCUzT3aVeYY", | ||
"properties": { | ||
"LIonCore_M3_NamespacedEntity_simpleName": "Library", | ||
"LIonCore_M3_Concept_abstract": false | ||
"LIonCore_M3_Concept_abstract": "false" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now _un_aligned with the TS-implementation, but we'll discuss this on Wednesday as well.
} else if (key.equals("properties")) { | ||
assertEquivalentObjects(expected.getAsJsonObject("properties"), actual.getAsJsonObject("properties"), "Properties of " + context); | ||
} else { | ||
throw new UnsupportedOperationException(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an AssertionError
(or even just a RuntimeException
) with a meaningful description along the line of pair ("${key}", ...) found in object but don't know what to assert about it
would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I will fix it
private void assertEquivalentLionWebJson(JsonArray expected, JsonArray actual) { | ||
Map<String, JsonObject> expectedElements = new HashMap<>(); | ||
Map<String, JsonObject> actualElements = new HashMap<>(); | ||
expected.forEach(e -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that some FP-style DRY could happen here: lines 79&81-84 are really very similar to lines 80&85-88.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I applied some changes to the serialization logic, some to the LionCore self definition and some to library-metamodel.json to ensure that reserializing this unserialized metamodel produce a JSON equivalent to the original JSON.
To verify the JSON is equivalent, even if not identical, I implemented some logic to compare the JSON and ignore irrelevant differences.