faunadb-csharp icon indicating copy to clipboard operation
faunadb-csharp copied to clipboard

Unable to decode Dictionary<string, object>

Open goncalo-oliveira opened this issue 3 years ago • 1 comments

Consider the following structure

public class Person
{
    public string Name { get; set; }
    public Dictionary<string, object> Metadata { get; set; }
}

The encoder doesn't seem to have an issue and serializes the dictionary correctly; here's the encoded value ToString().

ObjectV(name: StringV(Japanfy),metadata: ObjectV(comm.status: StringV(connected),comm.satellites: LongV(8)))

However, the decoder doesn't behave well with this and doesn't decode the values of the dictionary. It just creates an empty object for each.

{"Name":"Japanfy","Metadata":{"comm.status":{},"comm.satellites":{}}}

goncalo-oliveira avatar Jul 02 '21 13:07 goncalo-oliveira

As per discussed in the Slack channel...

What object should we use to decode when we find an object?

  • @marrony

If the value is a StringV, then it should be a string, for example.

When we are encoding, what matters is the actual object type. So, when we are decoding, shouldn't we consider using the value type?

goncalo-oliveira avatar Jul 02 '21 16:07 goncalo-oliveira