JSON Type not supported for int datatype --> JSON type not supported. (Parameter 'ValueKind')\r\nActual value was Number

684 views Asked by At

I have a class Person that has an Age property which is an int. It is persisted down to Cosmos Graph DB. I use the GremlinClient to fetch the record and then I have a Materialize method to rebuild <T>. If the Person class doesn't have any int types it works fine, however my method fails somewhere.

Coming back from the Graph, my result looks good:

enter image description here

Few things to note about the above:

  1. it is an IDictionary<string, object> and it has 4 entry.
  2. the 4th entry actually holds the properties of the Person object as they exist in the vertex in the graph enter image description here Few things to note:
  3. Although the resulting value in the dictionary entry (object) is a value "Bob", "Oak , 32, etc. it comes from the Gremlin client as System.Linq.Enumerable.SelectEnumerableIterator<System.Text.Json.JsonElement, object> which my method attempts to extract the value and then recreate <T> and return T.

Here's how I found it.link I have made some changes to this method but it still throws the same error, apparently its the SelectEnumerableIterator doesn't like Ints for some reason.

Hoping one of you can help me!

Error and Stack Trace:

    ActualValue: Number
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233086
    HelpLink: null
    InnerException: null
    Message: "JSON type not supported. (Parameter 'ValueKind')\r\nActual value was Number."
    ParamName: "ValueKind"
    Source: "Gremlin.Net"
    StackTrace: "   at Gremlin.Net.Structure.IO.GraphSON.GraphSONReader.ToObject(JsonElement graphSon)
\r\n   at Gremlin.Net.Structure.IO.GraphSON.GraphSONReader.<ReadDictionary>b__6_1(JsonProperty property)
\r\n   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
\r\n   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
\r\n   at Gremlin.Net.Structure.IO.GraphSON.GraphSONReader.ReadDictionary(JsonElement jsonDict)
\r\n   at Gremlin.Net.Structure.IO.GraphSON.GraphSONReader.ToObject(JsonElement graphSon)
\r\n   at Gremlin.Net.Structure.IO.GraphSON.GraphSONReader.<ToObject>b__4_0(JsonElement t)
\r\n   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()"    TargetSite: {System.Object ToObject(System.Text.Json.JsonElement)}
1

There are 1 answers

1
JohnStClair On

There's a discussion on the same issue here, and I've posted a work-around until Cosmos updates their support.