案例
我在Java中使用ResultSet的提交方法(由org.apache.tinkerpop提供:gremlin-driver:3.0.1-incubating dependency)来查询gremlin服务器。我需要知道如何配置我的客户端以接收JSON格式的响应。
我做了什么
我尝试过使用 GraphSONMessageSerializerV1d0 和 GraphSONMessageSerializerGremlinV1d0 序列化程序,但响应不是有效的json。这是我的gremlin-server.yaml文件
authentication: {className:
org.apache.tinkerpop.gremlin.server.auth.AllowAllAuthenticator,
config: null}
channelizer:
org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
graphs: {graph: src/test/resources/titan-inmemory.properties}
gremlinPool: 8
host: localhost
maxAccumulationBufferComponents: 1024
maxChunkSize: 8192
maxContentLength: 65536
maxHeaderSize: 8192
maxInitialLineLength: 4096
metrics:
consoleReporter: null
csvReporter: null
gangliaReporter: null
graphiteReporter: null
jmxReporter: null
slf4jReporter: {enabled: true, interval: 180000, loggerName:
org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics}
plugins: [aurelius.titan]
port: 8182
processors: []
resultIterationBatchSize: 64
scriptEngines:
gremlin-groovy:
config: null
imports: [java.lang.Math]
scripts: [src/test/resources/generate-asset-plus-locations.groovy]
staticImports: [java.lang.Math.PI]
scriptEvaluationTimeout: 30000
serializedResponseTimeout: 30000
serializers:
- className:
org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0
config: {useMapperFromGraph: graph}
- className:
org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0
config: {serializeResultToString: true}
- className:
org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializer
GremlinV1d0
config: {useMapperFromGraph: graph}
- className:
org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0
config: {useMapperFromGraph: graph}
ssl: {enabled: false, keyCertChainFile: null, keyFile: null, keyPassword:
null, trustCertChainFile: null}
threadPoolBoss: 1
threadPoolWorker: 1
writeBufferHighWaterMark: 65536
writeBufferLowWaterMark: 32768
如果有人帮我配置客户端以接收JSON格式的结果,那就太棒了!
答案 0 :(得分:1)
要使用GraphSON作为序列化格式,您只需将其指定给Cluster
构建器:
Cluster cluster = Cluster.build().serializer(Serializers.GRAPHSON_V2D0).create();
但它没有任何价值,因为它不会让你返回一串JSON来使用它。它告诉服务器使用JSON作为序列化格式,但驱动程序将JSON反序列化为对象(地图,列表等)。如果您想要一个实际的JSON字符串,那么您应该在脚本中返回一个发送到服务器的字符串。您唯一的另一个选择是编写自己的序列化程序,它始终只保留字符串。