我将示例顶点GraphSON的g:Vertex放在一个文件中:
$ cat vertex.json
{ "@type" : "g:Vertex", "@value" : { "id" : { "@type" : "g:Int32", "@value" : 1 }, "label" : "person", "properties" : { "name" : [ { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 0 }, "value" : "marko", "label" : "name" } } ], "location" : [ { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 6 }, "value" : "san diego", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 1997 }, "endTime" : { "@type" : "g:Int32", "@value" : 2001 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 7 }, "value" : "santa cruz", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2001 }, "endTime" : { "@type" : "g:Int32", "@value" : 2004 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 8 }, "value" : "brussels", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2004 }, "endTime" : { "@type" : "g:Int32", "@value" : 2005 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 9 }, "value" : "santa fe", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2005 } } } } ] } } }试图将其读入:
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
g.io("/home/ubuntu/vertex.json").read().iterate() 产生一个错误:
org.apache.tinkerpop.shaded.jackson.databind.JsonMappingException:无法按需要反序列化JSON值。嵌套异常: java.lang.InstantiationException:无法将包含在JSON (‘g:顶点’)中的检测类型的值反序列化为对象映射程序参数中指定的类型(接口java.util.Map)。这些类型是不相容的。资料来源:(ByteArrayInputStream);一行: 1,列: 36
我尝试使用graphson_reader和DriverRemoteConnection的message_serializer参数来指定GraphSONSerializersV3d0,但是我无法克服这个错误。
上面的示例顶点GraphSON如何从读取到图中?
发布于 2020-04-10 13:35:50
您是如何创建GraphSON的?可能值得使用TinkerGraph创建一个简单的GraphSON文件,并将您的文件与之进行比较,以确保语法正确。我使用下面的步骤创建JSON,如下所示。您的示例中的GraphSON看起来更像是查询结果,而不是描述图形的文件。总之,这里有一个例子:
gremlin> g.addV('test').property('name','some-name').property('age','some-age')
==>v[61015]
gremlin> g.io('test.json').write()
{"id":{"@type":"g:Int64","@value":61015},"label":"test","properties":{"name":[{"id":{"@type":"g:Int64","@value":61016},"value":"some-name"}],"age":[{"id":{"@type":"g:Int64","@value":61017},"value":"some-age"}]}}这里有一个指向Apache TinkerPop GraphSON参考文档的链接。
http://tinkerpop.apache.org/docs/3.4.6/dev/io/#graphson
https://stackoverflow.com/questions/61134072
复制相似问题