'Gremlin.NET deserialize number property

I have a query that creates a vertex and an edge "Created". The edge has a property "on" which is unix datetime long. When I execute a query with the following segment in the Azure Cosmos DB terminal, it works as expected - an object is returned with an "On" property that is a number.

.project('Id', 'CreatedOn')                    
   .by('id')                    
   .by(
     select('createdEdge')
       .by('on')
    ) 

When I execute this query from my application code using Gremlin.NET, it fails with the error:

JSON type not supported.

I see in the source code that the deserialization logic of Gremlin.NET does not seem to handle any number types. Is this really the case? Is there no way to use long, float, int property types?



Solution 1:[1]

Note there is a work-around as discussed here: https://www.mail-archive.com/[email protected]/msg22532.html

In short, you can create an custom reader derived from GraphSON2Reader:

public class CustomGraphSON2Reader : GraphSON2Reader
{
    public override dynamic ToObject(JsonElement graphSon) =>
        graphSon.ValueKind switch
        {
            // numbers
            JsonValueKind.Number when graphSon.TryGetInt32(out var intValue) => intValue,
            JsonValueKind.Number when graphSon.TryGetInt64(out var longValue) => longValue,
            JsonValueKind.Number when graphSon.TryGetDecimal(out var decimalValue) => decimalValue,
            

            _ => base.ToObject(graphSon)
       };
}

and then pass it into your client:

var client = new GremlinClient(server, new GraphSON2MessageSerializer(new CustomGraphSON2Reader()));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JohnStClair