-
Notifications
You must be signed in to change notification settings - Fork 33
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
Concept map JSON serialization #404
Concept map JSON serialization #404
Conversation
PR Review ChecklistDo not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed. Trivial Change
Code
Architecture
|
73fa39d
to
d7f5b54
Compare
@CheckReturnValue | ||
default JsonObject toJSON() { | ||
JsonObject object = Json.object(); | ||
map().forEach((resVar, resConcept) -> object.add(resVar, resConcept.toJSON())); | ||
return object; | ||
} |
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.
All implementations of toJSON()
are done in the api
package. Otherwise the implementation would be duplicated between e.g. ThingImpl
and ThingImpl.Remote
, since ...Impl.Remote
don't extend their enclosing counterparts.
private boolean JSONValuesAreEqual(JsonValue left, JsonValue right) { | ||
if (Objects.equals(left, right)) return true; | ||
if (left == null || right == null) return false; | ||
if (left.isObject() && right.isObject()) return JSONObjectsAreEqual(left.asObject(), right.asObject()); | ||
if (left.isArray() && right.isArray()) return JSONArraysAreEqual(left.asArray(), right.asArray()); | ||
return false; | ||
} | ||
|
||
private boolean JSONObjectsAreEqual(JsonObject left, JsonObject right) { | ||
if (left.size() != right.size()) return false; | ||
return left.names().stream().allMatch((name) -> JSONValuesAreEqual(left.get(name), right.get(name))); | ||
} | ||
|
||
private boolean JSONArraysAreEqual(JsonArray left, JsonArray right) { | ||
if (left.size() != right.size()) return false; | ||
for (int i = 0; i < left.size(); i++) | ||
if (!JSONValuesAreEqual(left.get(i), right.get(i))) return false; | ||
return 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.
JsonObject
s are ordered, and by default the comparison would respect the order of keys. Since we don't specify the order, we have to define our own equality check for JsonValue
s.
plugin = "pretty", | ||
glue = "com.vaticle.typedb.client.test.behaviour", | ||
features = "external/vaticle_typedb_behaviour/concept/serialization.feature", | ||
tags = "not @ignore and not @ignore-typedb" |
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.
Can you double check the @ignore-typedb
is correct here? I think we have one for client-java or clients specifically or something? Might as well do a drive-by of the other BDD tests in this repo while you're at it
What is the goal of this PR?
We implement the JSON serialization of concept maps according to typedb/typedb-behaviour#238.