Ran*_*ize 1 java neo4j neo4j-bolt
我正在使用Java Bolt驱动程序(1.0.1),并且想知道是否有一种方法可以将结果转换为Json(可能与REST API中的相同)吗?
我试图以gson这种方式使用:
Result r = null;
try ( Transaction tx = graphDb.beginTx() )
{
r = graphDb.execute("MATCH...");
tx.success();
} catch {...}
new Gson().toJson(result);
Run Code Online (Sandbox Code Playgroud)
但是我得到的是:
java.lang.StackOverflowError
at com.google.gson.internal.$Gson$Types.canonicalize($Gson$Types.java:98)
at com.google.gson.reflect.TypeToken.<init>(TypeToken.java:72)
etc...
Run Code Online (Sandbox Code Playgroud)
您显示的API不是Bolt-Driver,而是嵌入式Java-API。
在螺栓驱动器中,您可以执行
Driver driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "neo4j" ) );
Session session = driver.session();
StatementResult result = session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" );
while ( result.hasNext() ) {
Record record = result.next();
gson.toJson(record.asMap());
}
session.close();
driver.close();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3449 次 |
| 最近记录: |