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:
Few things to note about the above:
- it is an
IDictionary<string, object>
and it has 4 entry. - the 4th entry actually holds the properties of the
Person
object as they exist in thevertex
in the graph Few things to note: - Although the resulting value in the dictionary entry (
object
) is a value "Bob", "Oak , 32, etc. it comes from the Gremlin client asSystem.Linq.Enumerable.SelectEnumerableIterator<System.Text.Json.JsonElement, object>
which my method attempts to extract the value and then recreate<T>
and returnT
.
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 Int
s 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)}
There's a discussion on the same issue here, and I've posted a work-around until Cosmos updates their support.