首页 > 解决方案 > JanusGraph 3.x graphson 导入在美化 json 上失败

问题描述

将美化的 json/graphson 导入 JanusGraph 是否有其他人有此问题?

完全相同但未美化的文件(无回车、制表符、空格)将完美导入,但如果美化它会失败并出现以下错误:

graph.io(graphson()).readGraph("data/tgraph2.json")

Could not deserialize the JSON value as required. Nested exception: java.lang.InstantiationException: Cannot deserialize the value with the detected type contained in the JSON ('tinker:graph') to the type specified in parameter to the object mapper (class java.util.LinkedHashMap). Those types are incompatible. at [Source: (ByteArrayInputStream); line: 1, column: 3]

请注意,编辑文件以手动删除第一个换行符并将错误消息更改为... at [Source: (ByteArrayInputStream); line: 1, column: 12]etc - 所以这绝对是文件中的空格问题。

版本 3.x

当然,这不是理想的行为。无论是用空格美化还是缩小,json 都应该同样有效。

标签: gremlinjanusgraphgremlin-servergraphson

解决方案


需要注意的是,GraphSON 有两种形式。在一种形式中,整个文件不是单个 JSON 文档,而是每一行。每条线代表一个顶点的邻接表。

这是默认的 GraphSON 格式,它是为流式设计的,因此文件可以很容易地被分解以进行多线程操作。另一种形式是包含所有顶点和所有边的单个 JSON 文档。

格式记录在这里

http://tinkerpop.apache.org/docs/3.4.1/dev/io/#graphson


推荐阅读