Closed alexbk66 closed 2 weeks ago
I was able to resolve the issue by making the following change. I'm sure someone with a knowledge of Linq could do it a lot better.
public override Dictionary<string, string> ReadJson(JsonReader reader, Type objectType, Dictionary<string, string> existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var array = serializer.Deserialize<string[][]>(reader);
if (array == null ||
array.Length == 0)
{
return new Dictionary<string, string>();
}
// fixes System.ArgumentException: An item with the same key has already been added.
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (var item in array)
{
if (!dict.ContainsKey(item[0]))
{
dict.Add(item[0], item[1]);
}
}
return dict;
// return array.ToDictionary(x => x[0], x => x.Length > 1 ? x[1] : null);
}
}
I was able to resolve the issue by making the following change. I'm sure someone with a knowledge of Linq could do it a lot better.
That's not a fix - it's a workaround. I added exception handler instead (workaround as well).
@alexbk66 This issue should be fixed in the linked PR
I added serialisation exception handler in JsonSerializerSettings to diagnose the problem - example of json causing the issue:
[["zwave_js","3636836764-1-0:4:4"],["zwave_js","3636836764-1"]]
Type: 'Device' path '[654].identifiers'