0

我有以下名为 GraphSON 的文件input.json

{"label":"Thing","properties":{"foo":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Set","@value":[]}}]}}

在 Java 中,我尝试org.apache.tinkerpop.tinkergraph-gremlin:3.4.10使用以下代码将上述 GraphSON 文件加载到内存图 ( ) 中:

Graph graph = TinkerGraph.open();
GraphTraversalSource g = traversal().withGraph(graph);
g.io("input.json").read().iterate();

但是,运行时遇到以下反序列化错误:

java.lang.RuntimeException: org.apache.tinkerpop.shaded.jackson.databind.JsonMappingException: Could not deserialize the JSON value as required. Nested exception: org.apache.tinkerpop.shaded.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token
 at [Source: (ByteArrayInputStream); line: 1, column: 110]
 at [Source: (ByteArrayInputStream); line: 1, column: 110] (through reference chain: java.util.LinkedHashMap["properties"]->java.util.LinkedHashMap["foo"]->java.util.ArrayList[0]->java.util.LinkedHashMap["value"])

如果我在 GraphSON 文件中更改{"@type":"g:Set","@value":[]}[],我不再收到错误,但现在图中的值是 aList而不是 a Set

这是我能找到的关于该主题的唯一文档,但它并没有帮助我找到解决方案: http: //tinkerpop.apache.org/docs/3.4.1/dev/io/#_set

我试图g:Set通过以编程方式创建图形然后将其写入文件来让序列化程序为我创建一个有效属性,但生成的文件不包含g:Set,而是List

Graph graph = TinkerGraph.open();
GraphTraversalSource g = traversal().withGraph(graph);
g.addV("Thing").property("foo", Set.of("bar")).iterate();
g.io("output.json").write().iterate();
{"id":{"@type":"g:Int64","@value":0},"label":"Thing","properties":{"foo":[{"id":{"@type":"g:Int64","@value":1},"value":["bar"]}]}}

我错过了什么?

4

0 回答 0