我正在尝试将GraphResultSet对象转换为类似于datastax studio返回的JSON格式。我在试着用Graphson是否有将结果对象转换为JSON的示例代码?
我尝试了以下来自tikerpop蓝图的方法,但不起作用
List<GraphNode> gf=((GraphResultSet) resultSet).all();
Vertex v = (Vertex) gf.get(0).asVertex();
JSONObject json = null;
try {
json = GraphSONUtility.jsonFromElement((Element) v,getElementPropertyKeys((Element) v, false), GraphSONMode.COMPACT);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}我从dse得到一个GraphResultSet对象,它有顶点和边。我想以JSON格式输出。
发布于 2018-01-16 22:08:06
你不能直接在com.datastax.driver.dse.graph.DefaultVertex和com.tinkerpop.blueprints.Element之间进行转换。
DSE Java驱动程序中的GraphSONUtils类(src)应该能够处理这些转换。但因为它在“内部”包中,所以我预计随时都可能发生更改。
发布于 2018-01-20 05:28:42
目前还没有将DSE驱动程序图形对象转换为JSON的直接方法。但是,如果使用DSE driver 1.5.0,如果您正在寻找简单的GraphSON1响应,则可以将驱动程序配置为使用JSON。然后简单地输出GraphNode的字符串表示
DseCluster dseCluster = DseCluster.builder().addContactPoint("127.0.0.1")
.withGraphOptions(
new GraphOptions()
.setGraphName("demo")
// GraphSON version is set here:
.setGraphSubProtocol(GraphProtocol.GRAPHSON_1_0)
)
.build();
DseSession dseSession = dseCluster.connect();
// create query
GraphStatement graphStatement = [.....];
GraphResultSet resultSet = dseSession.executeGraph(graphStatement);
for (GraphNode gn : resultSet) {
String json = gn.toString();
}https://stackoverflow.com/questions/48275770
复制相似问题