This project is read-only.
1

Closed

Dictionary<string, byte[]> causes InvalidCastException

description

FastJSON correctly serializes the byte array to base64 but cannot read it back.
var jsonString = JSON.ToJSON(new Dictionary<string, byte[]>
{ 
    { "Test", new byte[10] },
    { "Test 2", new byte[0] }
});

var savedDictionary = JSON.ToObject<Dictionary<string, byte[]>>(jsonString);
Produces:
A first chance exception of type 'System.InvalidCastException' occurred in fastJSON.dll

Additional information: Unable to cast object of type 'System.String' to type 'System.Collections.Generic.List`1[System.Object]'.
The error is in fastJSON.deserializer.RootDictionary:
else if (t2.IsArray)
    v = CreateArray((List<object>)kv.Value, t2, t2.GetElementType(), null);
If (t2 == typeof(byte[]) && kv.Value is string), this code needs to take a different path.
Closed Jul 15, 2016 at 3:19 PM by MGholam
Fixed in 2.1.17

comments