How to modify Janusgraph(Gremlin) server API response, array of strings

127 views Asked by At

Recently, I've upgraded Janusgraph to version 0.5.2, it supports the Serializer versions GryoMessageSerializerV3d0, ..V2, ..V1 (Backwards compatibility). In the version3 response for the datatypes strings and array of strings, response format is same. I want the response to be separated.

Current response format(v3):

"@type": "g:Map",
"@value": [
    "_id", // string
    {
        "@type": "g:List",
        "@value": [
            "id1"
        ]
    },
    "names", // array of strings
    {
        "@type": "g:List",
        "@value": [
            "Name1", "Name2"
        ]
    },
    
]

For both datatypes, the response format is {"@type": "g:List",}. My requirement is how can I distinguish the whether datatype is array/string. I can't check for the each key in loop, it won't be proper solution considering there are large number of array datatypes. Is there anything which can be configured at the serialization level. Any other solution to separate the response(Array as array and String as string).

Note: Even for the other serialization versions(v2, v1) there is no differentiation, but response style is different(["id1"], ["Name1", "Name2"]). Everything is array of strings.

Thanks.

1

There are 1 answers

0
stephen mallette On

We chose to treat arrays as List for GraphSON and GraphBinary. You would have to write your own custom serializer plugin to GraphSON. You can see what is involved in developing one by looking at JanusGraph code a bit. You need custom serializer/deserializer instances and a Module to expose them to GraphSON. You can then construct the GraphSONMapper with addCustomModule(). You hand that mapper builder instance to a new GraphSONMessageSerializer.

For the server that means adding your own IoRegistry (JanusGraph example [here])4 and adding that to the Gremlin Server configuration file.

For the driver that means constructing the GraphSONMessageSerializer manually then when constructing the Cluster object with the Builder using the serializer(MessageSerializer) option to supply your instance.

As an alternative you could use Gryo which I believe will preserver the array type, but note that:

  1. Gryo is deprecated. There are no plans to remove it completely but the preference for a binary format is GraphBinary (though that does not support arrays as I mentioned earlier.
  2. Gryo only works on the JVM. There is no support for Python, .NET, etc.