Support for custom non-generic class implementing IDictionary<TKey,TValue>
TheRSP opened this issue · 0 comments
TheRSP commented
Currently, Utf8Json supports serialising to and from classes implementing System.Collections.Generic.IDictionary<,>
if and only if that class has two generic type arguments. I ask whether that restriction could be lifted?
Given the class
class MyDictionary: IDictionary<string, object>{
// ...
}
The following test should pass
// using FluentAssertions
[Test]
public void Can_deserialise_with_Utf8Json()
{
var Subject = new MyDictionary();
Subject.Add("a", "alpha");
Subject.Add("b", 2);
Subject.Add("c", new object());
var serialised = Utf8Json.JsonSerializer.Serialize(Subject);
var deserialised = Utf8Json.JsonSerializer.Deserialize<MyDictionary>(serialised);
deserialised.Should().BeEquivalentTo(Subject);
}
Currently, I can only achieve this if I also implement System.Collections.IDictionary