Skip to content

Commit

Permalink
Make properties optional in GraphSONv4 again CTR
Browse files Browse the repository at this point in the history
  • Loading branch information
kenhuuu committed Oct 3, 2024
1 parent f0e973d commit c48b36a
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 135 deletions.
98 changes: 34 additions & 64 deletions docs/src/dev/io/graphson.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ JSON String form of UUID.
==== Edge
JSON Object (required keys are: id, label, inVLabel, outVLabel, inV, outV, properties) +
JSON Object (required keys are: id, label, inVLabel, outVLabel, inV, outV) +
"id", "inV", "outV" is any GraphSON 4.0 type +
"label", "inVLabel", "outVLabel" value is a `g:List` of `String` +
"properties" is an Object containing Arrays of `g:Property`
"properties" is an optional Object containing Arrays of `g:Property`
The untyped version has one additional required key "type" which is always "vertex".
Expand Down Expand Up @@ -534,8 +534,7 @@ two required keys: "vertices" and "edges" +
"value": "marko",
"label": [
"name"
],
"properties": {}
]
}
}
],
Expand Down Expand Up @@ -654,8 +653,7 @@ two required keys: "vertices" and "edges" +
"value": "stephen",
"label": [
"name"
],
"properties": {}
]
}
}
],
Expand Down Expand Up @@ -751,8 +749,7 @@ two required keys: "vertices" and "edges" +
"value": "matthias",
"label": [
"name"
],
"properties": {}
]
}
}
],
Expand Down Expand Up @@ -871,8 +868,7 @@ two required keys: "vertices" and "edges" +
"value": "daniel",
"label": [
"name"
],
"properties": {}
]
}
}
],
Expand Down Expand Up @@ -968,8 +964,7 @@ two required keys: "vertices" and "edges" +
"value": "gremlin",
"label": [
"name"
],
"properties": {}
]
}
}
]
Expand Down Expand Up @@ -998,8 +993,7 @@ two required keys: "vertices" and "edges" +
"value": "tinkergraph",
"label": [
"name"
],
"properties": {}
]
}
}
]
Expand Down Expand Up @@ -1551,8 +1545,7 @@ two required keys: "vertices" and "edges" +
"outV": {
"@type": "g:Int32",
"@value": 10
},
"properties": {}
}
}
}
]
Expand All @@ -1574,8 +1567,7 @@ two required keys: "vertices" and "edges" +
"name": [
{
"id": 0,
"value": "marko",
"properties": {}
"value": "marko"
}
],
"location": [
Expand Down Expand Up @@ -1623,8 +1615,7 @@ two required keys: "vertices" and "edges" +
"name": [
{
"id": 1,
"value": "stephen",
"properties": {}
"value": "stephen"
}
],
"location": [
Expand Down Expand Up @@ -1664,8 +1655,7 @@ two required keys: "vertices" and "edges" +
"name": [
{
"id": 2,
"value": "matthias",
"properties": {}
"value": "matthias"
}
],
"location": [
Expand Down Expand Up @@ -1713,8 +1703,7 @@ two required keys: "vertices" and "edges" +
"name": [
{
"id": 3,
"value": "daniel",
"properties": {}
"value": "daniel"
}
],
"location": [
Expand Down Expand Up @@ -1754,8 +1743,7 @@ two required keys: "vertices" and "edges" +
"name": [
{
"id": 4,
"value": "gremlin",
"properties": {}
"value": "gremlin"
}
]
}
Expand All @@ -1770,8 +1758,7 @@ two required keys: "vertices" and "edges" +
"name": [
{
"id": 5,
"value": "tinkergraph",
"properties": {}
"value": "tinkergraph"
}
]
}
Expand Down Expand Up @@ -2051,8 +2038,7 @@ two required keys: "vertices" and "edges" +
"software"
],
"inV": 11,
"outV": 10,
"properties": {}
"outV": 10
}
]
}
Expand Down Expand Up @@ -2098,8 +2084,7 @@ Object with two required keys: "labels" and "objects" +
},
"label": [
"person"
],
"properties": {}
]
}
},
{
Expand All @@ -2111,8 +2096,7 @@ Object with two required keys: "labels" and "objects" +
},
"label": [
"software"
],
"properties": {}
]
}
},
{
Expand All @@ -2124,8 +2108,7 @@ Object with two required keys: "labels" and "objects" +
},
"label": [
"software"
],
"properties": {}
]
}
}
]
Expand All @@ -2148,24 +2131,21 @@ Object with two required keys: "labels" and "objects" +
"label": [
"person"
],
"type": "vertex",
"properties": {}
"type": "vertex"
},
{
"id": 10,
"label": [
"software"
],
"type": "vertex",
"properties": {}
"type": "vertex"
},
{
"id": 11,
"label": [
"software"
],
"type": "vertex",
"properties": {}
"type": "vertex"
}
]
}
Expand Down Expand Up @@ -2233,8 +2213,7 @@ JSON Object with one or more possibly nested "key" "value" pairs
"value": "gremlin",
"label": [
"name"
],
"properties": {}
]
}
}
]
Expand Down Expand Up @@ -2267,8 +2246,7 @@ JSON Object with one or more possibly nested "key" "value" pairs
"value": "tinkergraph",
"label": [
"name"
],
"properties": {}
]
}
}
]
Expand Down Expand Up @@ -2301,8 +2279,7 @@ JSON Object with one or more possibly nested "key" "value" pairs
"name": [
{
"id": 4,
"value": "gremlin",
"properties": {}
"value": "gremlin"
}
]
}
Expand All @@ -2319,8 +2296,7 @@ JSON Object with one or more possibly nested "key" "value" pairs
"name": [
{
"id": 5,
"value": "tinkergraph",
"properties": {}
"value": "tinkergraph"
}
]
}
Expand All @@ -2337,7 +2313,7 @@ JSON Object with one or more possibly nested "key" "value" pairs
JSON Object with required keys: "id", "label", "properties" +
"id" is any GraphSON 4.0 type +
"label" is a `g:List` of `String` +
"properties" is an Object containing Arrays of `g:VertexProperty`
"properties" is an optional Object containing Arrays of `g:VertexProperty`
The untyped version has one additional required key "type" which is always "vertex".
Expand Down Expand Up @@ -2365,8 +2341,7 @@ The untyped version has one additional required key "type" which is always "vert
"value": "marko",
"label": [
"name"
],
"properties": {}
]
}
}
],
Expand Down Expand Up @@ -2477,8 +2452,7 @@ The untyped version has one additional required key "type" which is always "vert
"name": [
{
"id": 0,
"value": "marko",
"properties": {}
"value": "marko"
}
],
"location": [
Expand Down Expand Up @@ -2524,7 +2498,7 @@ JOSN Object with required keys: "id", "value", "label", "properties" +
"id" is any type GraphSON 4.0 type +
"value" is any type GraphSON 4.0 type +
"label" is a `g:List` of `String` +
"properties" is an Object containing Arrays of "g:Property" (metaproperties)
"properties" is an optional Object containing Arrays of "g:Property" (metaproperties)
[source,json]
----
Expand All @@ -2538,8 +2512,7 @@ JOSN Object with required keys: "id", "value", "label", "properties" +
"value": "marko",
"label": [
"name"
],
"properties": {}
]
}
}
----
Expand All @@ -2551,8 +2524,7 @@ JOSN Object with required keys: "id", "value", "label", "properties" +
"value": "marko",
"label": [
"name"
],
"properties": {}
]
}
----
Expand Down Expand Up @@ -2683,8 +2655,7 @@ The following `ResponseMessage` is a typical example of the typical successful r
"value": "marko",
"label": [
"name"
],
"properties": {}
]
}
}
],
Expand Down Expand Up @@ -2805,8 +2776,7 @@ The following `ResponseMessage` is a typical example of the typical successful r
"name": [
{
"id": 0,
"value": "marko",
"properties": {}
"value": "marko"
}
],
"location": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public void serialize(final Vertex vertex, final JsonGenerator jsonGenerator, fi
}

private void writeProperties(final Vertex vertex, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException {
if (vertex.keys().size() == 0)
return;
jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES);
jsonGenerator.writeStartObject();

Expand Down Expand Up @@ -172,23 +174,25 @@ private void writeProperties(final Edge edge, final JsonGenerator jsonGenerator)
final Iterator<Property<Object>> elementProperties = normalize ?
IteratorUtils.list(edge.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : edge.properties();

jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES);
jsonGenerator.writeStartObject();
if (elementProperties.hasNext()) {
jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES);
jsonGenerator.writeStartObject();

while (elementProperties.hasNext()) {
final Property prop = elementProperties.next();
jsonGenerator.writeFieldName(prop.key());
jsonGenerator.writeStartArray();
while (elementProperties.hasNext()) {
final Property prop = elementProperties.next();
jsonGenerator.writeFieldName(prop.key());
jsonGenerator.writeStartArray();

if (typeInfo == TypeInfo.NO_TYPES) {
jsonGenerator.writeObject(prop.value());
} else {
jsonGenerator.writeObject(prop);
}
if (typeInfo == TypeInfo.NO_TYPES) {
jsonGenerator.writeObject(prop.value());
} else {
jsonGenerator.writeObject(prop);
}

jsonGenerator.writeEndArray();
jsonGenerator.writeEndArray();
}
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndObject();
}
}

Expand Down Expand Up @@ -246,11 +250,14 @@ private static void tryWriteMetaProperties(final VertexProperty property, final
// when "detached" you can't check features of the graph it detached from so it has to be
// treated differently from a regular VertexProperty implementation.
if (property instanceof DetachedVertexProperty) {
writeMetaProperties(property, jsonGenerator, normalize);
// only write meta properties key if they exist
if (property.properties().hasNext()) {
writeMetaProperties(property, jsonGenerator, normalize);
}
} else {
// still attached - so we can check the features to see if it's worth even trying to write the
// meta properties key
if (property.graph().features().vertex().supportsMetaProperties()) {
if (property.graph().features().vertex().supportsMetaProperties() && property.properties().hasNext()) {
writeMetaProperties(property, jsonGenerator, normalize);
}
}
Expand Down
Loading

0 comments on commit c48b36a

Please sign in to comment.