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

kenhuuu pushed a commit to branch master-http-final
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit c12b33f9d57d2bd6e3faddf4f013e61f0eedfc38
Author: kenhuuu <[email protected]>
AuthorDate: Tue Oct 29 12:55:04 2024 -0700

    Update BulkSet GraphSONv4 serialization. (#2861)
---
 docs/src/dev/io/graphson.asciidoc                  | 24 ++++++++++++++++-
 .../structure/io/graphson/GraphSONModule.java      |  6 +++--
 .../io/graphson/TraversalSerializersV4.java        | 31 ++--------------------
 .../graphson/GraphSONMapperEmbeddedTypeTest.java   |  7 ++---
 .../structure/io/graphson/empty-bulklist-v4.json   |  4 +++
 .../structure/io/graphson/empty-bulkset-v4.json    |  4 ---
 .../structure/io/graphson/var-bulklist-v4.json     |  4 +++
 .../structure/io/graphson/var-bulkset-v4.json      | 10 -------
 .../io/AbstractTypedCompatibilityTest.java         |  2 --
 9 files changed, 41 insertions(+), 51 deletions(-)

diff --git a/docs/src/dev/io/graphson.asciidoc 
b/docs/src/dev/io/graphson.asciidoc
index 8d70cd2509..cede81a2da 100644
--- a/docs/src/dev/io/graphson.asciidoc
+++ b/docs/src/dev/io/graphson.asciidoc
@@ -2615,7 +2615,7 @@ The untyped version has one additional required key 
"type" which is always "vert
 
 ==== VertexProperty
 
-JOSN Object with required keys: "id", "value", "label", "properties" +
+JSON 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` +
@@ -2651,6 +2651,28 @@ JOSN Object with required keys: "id", "value", "label", 
"properties" +
 
 === Graph Process
 
+==== BulkSet
+
+JSON Array that contains the expanded entries of the BulkSet.
+Note: BulkSet is serialized to g:List so there is no BulkSet deserializer.
+
+[source,json]
+----
+{
+  "@type": "g:List",
+  "@value": [
+    "marko",
+    "josh",
+    "josh"
+  ]
+}
+----
+
+[source,json]
+----
+[ "marko", "josh", "josh" ]
+----
+
 ==== Direction
 
 JSON String of the enum value.
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index 904809360d..b19cbb4931 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -149,6 +149,10 @@ abstract class GraphSONModule extends 
TinkerPopJacksonModule {
                     put(Double.class, "Double");
                     put(Float.class, "Float");
 
+                    // BulkSet is expanded to List during serialization but we 
want the List deserializer to be
+                    // registered to g:List so this entry must be added before 
List.
+                    put(BulkSet.class, "List");
+
                     put(Map.class, "Map");
                     put(List.class, "List");
                     put(Set.class, "Set");
@@ -165,7 +169,6 @@ abstract class GraphSONModule extends 
TinkerPopJacksonModule {
                     put(TraversalExplanation.class, "TraversalExplanation");
                     put(Traverser.class, "Traverser");
                     put(Tree.class, "Tree");
-                    put(BulkSet.class, "BulkSet");
                     put(AndP.class, "P");
                     put(OrP.class, "P");
                     put(P.class, "P");
@@ -299,7 +302,6 @@ abstract class GraphSONModule extends 
TinkerPopJacksonModule {
             addDeserializer(Double.class, new 
GraphSONSerializersV4.DoubleJacksonDeserializer());
 
             // traversal
-            addDeserializer(BulkSet.class, new 
TraversalSerializersV4.BulkSetJacksonDeserializer());
             Stream.of(VertexProperty.Cardinality.values(),
                     Column.values(),
                     Direction.values(),
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV4.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV4.java
index 041824525d..fec60d2aa8 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV4.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV4.java
@@ -152,9 +152,8 @@ final class TraversalSerializersV4 {
         public void serialize(final BulkSet bulkSet, final JsonGenerator 
jsonGenerator, final SerializerProvider serializerProvider)
                 throws IOException {
             jsonGenerator.writeStartArray();
-            for (Map.Entry entry : (Set<Map.Entry>) 
bulkSet.asBulk().entrySet()) {
-                jsonGenerator.writeObject(entry.getKey());
-                jsonGenerator.writeObject(entry.getValue());
+            for (Object element : bulkSet) {
+                jsonGenerator.writeObject(element);
             }
             jsonGenerator.writeEndArray();
         }
@@ -401,32 +400,6 @@ final class TraversalSerializersV4 {
         }
     }
 
-    final static class BulkSetJacksonDeserializer extends 
StdDeserializer<BulkSet> {
-        public BulkSetJacksonDeserializer() {
-            super(BulkSet.class);
-        }
-
-        @Override
-        public BulkSet deserialize(final JsonParser jsonParser, final 
DeserializationContext deserializationContext) throws IOException, 
JsonProcessingException {
-
-            final BulkSet<Object> bulkSet = new BulkSet<>();
-
-            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
-                final Object key = 
deserializationContext.readValue(jsonParser, Object.class);
-                jsonParser.nextToken();
-                final Long val = deserializationContext.readValue(jsonParser, 
Long.class);
-                bulkSet.add(key, val);
-            }
-
-            return bulkSet;
-        }
-
-        @Override
-        public boolean isCachable() {
-            return true;
-        }
-    }
-
     static class TraverserJacksonDeserializer extends 
StdDeserializer<Traverser> {
 
         public TraverserJacksonDeserializer() {
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
index b6ae2dc189..94086371dc 100644
--- 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
@@ -119,15 +119,16 @@ public class GraphSONMapperEmbeddedTypeTest extends 
AbstractGraphSONTest {
 
     @Test
     public void shouldHandleBulkSet() throws Exception {
-        // only supported on V3/V4
-        assumeThat(version, not(anyOf(startsWith("v1"), startsWith("v2"))));
+        // only supported on V4
+        assumeThat(version, not(anyOf(startsWith("v1"), startsWith("v2"), 
startsWith("v3"))));
 
         final BulkSet<String> bs = new BulkSet<>();
         bs.add("test1", 1);
         bs.add("test2", 2);
         bs.add("test3", 3);
 
-        assertEquals(bs, serializeDeserialize(mapper, bs, BulkSet.class));
+        final List<String> expandedBs = new ArrayList<>(bs);
+        assertEquals(expandedBs, serializeDeserializeAuto(mapper, bs));
     }
 
     @Test
diff --git 
a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/empty-bulklist-v4.json
 
b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/empty-bulklist-v4.json
new file mode 100644
index 0000000000..aacbd803fb
--- /dev/null
+++ 
b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/empty-bulklist-v4.json
@@ -0,0 +1,4 @@
+{
+  "@type" : "g:List",
+  "@value" : [ ]
+}
\ No newline at end of file
diff --git 
a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/empty-bulkset-v4.json
 
b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/empty-bulkset-v4.json
deleted file mode 100644
index f9fb4a5eed..0000000000
--- 
a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/empty-bulkset-v4.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-  "@type" : "g:BulkSet",
-  "@value" : [ ]
-}
\ No newline at end of file
diff --git 
a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/var-bulklist-v4.json
 
b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/var-bulklist-v4.json
new file mode 100644
index 0000000000..ac763480b2
--- /dev/null
+++ 
b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/var-bulklist-v4.json
@@ -0,0 +1,4 @@
+{
+  "@type" : "g:List",
+  "@value" : [ "marko", "josh", "josh" ]
+}
\ No newline at end of file
diff --git 
a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/var-bulkset-v4.json
 
b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/var-bulkset-v4.json
deleted file mode 100644
index c216a36171..0000000000
--- 
a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/var-bulkset-v4.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
-  "@type" : "g:BulkSet",
-  "@value" : [ "marko", {
-    "@type" : "g:Int64",
-    "@value" : 1
-  }, "josh", {
-    "@type" : "g:Int64",
-    "@value" : 2
-  } ]
-}
\ No newline at end of file
diff --git 
a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
 
b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
index 3b7bdf9093..bd8dee9cb4 100644
--- 
a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
+++ 
b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
@@ -882,7 +882,6 @@ public abstract class AbstractTypedCompatibilityTest 
extends AbstractCompatibili
     }
 
     @Test
-    @Ignore("re-enable after GraphSONV4 bulklist is implemented")
     public void shouldReadWriteVarBulkList() throws Exception {
         final String resourceName = "var-bulklist";
 
@@ -898,7 +897,6 @@ public abstract class AbstractTypedCompatibilityTest 
extends AbstractCompatibili
     }
 
     @Test
-    @Ignore("re-enable after GraphSONV4 bulklist is implemented")
     public void shouldReadWriteEmptyBulkList() throws Exception {
         final String resourceName = "empty-bulklist";
 

Reply via email to