You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by xi...@apache.org on 2024/10/25 16:57:02 UTC

(tinkerpop) 01/03: update element label serialization

This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a commit to branch py-graphsonv4-updates
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 758cc3075e92400b5907ec6fa2b69308e303b9aa
Author: Yang Xia <55...@users.noreply.github.com>
AuthorDate: Thu Oct 24 09:30:12 2024 -0700

    update element label serialization
---
 .../main/python/gremlin_python/driver/serializer.py  |  7 +++++--
 .../python/gremlin_python/structure/io/graphsonV4.py | 20 ++++++++++----------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/gremlin-python/src/main/python/gremlin_python/driver/serializer.py b/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
index 9aa4a7c0cc..6275dda9f5 100644
--- a/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
+++ b/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
@@ -73,8 +73,11 @@ class GraphSONSerializerV4(object):
         return message
 
     def build_message(self, fields, gremlin):
-        message = fields
-        message['gremlin'] =  gremlin
+        message = {
+            'gremlin': gremlin
+        }
+        for k, v in fields.items():
+            message[k] = self._graphson_writer.to_dict(v)
         return self.finalize_message(message)
 
     def finalize_message(self, message):
diff --git a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py
index b4aa99bf8e..4c7b0616d6 100644
--- a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py
+++ b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py
@@ -69,6 +69,10 @@ class GraphSONUtil(object):
     def format_type(cls, prefix, type_name):
         return "%s:%s" % (prefix, type_name)
 
+    @classmethod
+    def write_label(cls, value):
+        return [value]
+
 
 # Read/Write classes split to follow precedence of the Java API
 class GraphSONWriter(object):
@@ -180,7 +184,7 @@ class VertexSerializer(_GraphSONTypeIO):
     @classmethod
     def dictify(cls, vertex, writer):
         return GraphSONUtil.typed_value("Vertex", {"id": writer.to_dict(vertex.id),
-                                                  "label": writer.to_dict([vertex.label])})
+                                                  "label": GraphSONUtil.write_label(vertex.label)})
 
 
 class EdgeSerializer(_GraphSONTypeIO):
@@ -190,15 +194,10 @@ class EdgeSerializer(_GraphSONTypeIO):
     @classmethod
     def dictify(cls, edge, writer):
         return GraphSONUtil.typed_value("Edge", {"id": writer.to_dict(edge.id),
-                                                 "label": writer.to_dict([edge.label]),
+                                                 "label": GraphSONUtil.write_label(edge.label),
                                                  "inV": writer.to_dict(edge.inV),
                                                  "outV": writer.to_dict(edge.outV)})
 
-                                                # "outV": writer.to_dict(edge.outV.id),
-                                                # "outVLabel": writer.to_dict([edge.outV.label]),
-                                                # "inV": writer.to_dict(edge.inV.id),
-                                                # "inVLabel": writer.to_dict([edge.inV.label])})
-
 
 class VertexPropertySerializer(_GraphSONTypeIO):
     python_type = VertexProperty
@@ -207,7 +206,7 @@ class VertexPropertySerializer(_GraphSONTypeIO):
     @classmethod
     def dictify(cls, vertex_property, writer):
         return GraphSONUtil.typed_value("VertexProperty", {"id": writer.to_dict(vertex_property.id),
-                                                          "label": writer.to_dict([vertex_property.label]),
+                                                          "label": GraphSONUtil.write_label(vertex_property.label),
                                                           "value": writer.to_dict(vertex_property.value),
                                                           "vertex": writer.to_dict(vertex_property.vertex.id)})
 
@@ -650,10 +649,11 @@ class EdgeDeserializer(_GraphSONTypeIO):
             properties = reader.to_object(d["properties"])
             if properties is not None:
                 properties = list(properties.values())
+
         return Edge(reader.to_object(d["id"]),
-                    Vertex(reader.to_object(d["outV"]), d.get("outVLabel", "vertex")[0]),
+                    Vertex(reader.to_object(d["outV"]).get("id"), reader.to_object(d["outV"]).get("label")[0]),
                     d.get("label", "edge")[0],
-                    Vertex(reader.to_object(d["inV"]), d.get("inVLabel", "vertex")[0]),
+                    Vertex(reader.to_object(d["inV"]).get("id"), reader.to_object(d["outV"]).get("label")[0]),
                     properties)