Fixes #7701: System.Text.Json can't deserialize properties of EtoBase class.

pull/7702/head
Halil İbrahim Kalkan 5 years ago
parent 2f64f74f2a
commit 1780bba764

@ -6,11 +6,11 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
[Serializable]
public abstract class EtoBase
{
public Dictionary<string, object> Properties { get; }
public Dictionary<string, string> Properties { get; set; }
protected EtoBase()
{
Properties = new Dictionary<string, object>();
Properties = new Dictionary<string, string>();
}
}
}

@ -63,6 +63,23 @@ namespace Volo.Abp.Json
json.ShouldContain("SystemTextJson");
}
[Fact]
public void SystemTextJsonSerialize_With_Dictionary_Test()
{
var json = _jsonSerializer.Serialize(new MyClassWithDictionary
{
Properties =
{
{"A", "AV"},
{"B", "BV"}
}
});
var deserialized = _jsonSerializer.Deserialize<MyClassWithDictionary>(json);
deserialized.Properties.ShouldContain(p => p.Key == "A" && p.Value == "AV");
deserialized.Properties.ShouldContain(p => p.Key == "B" && p.Value == "BV");
}
public class MyClass1
{
@ -83,6 +100,16 @@ namespace Volo.Abp.Json
public string Provider { get; set; }
}
public class MyClassWithDictionary
{
public Dictionary<string, string> Properties { get; set; }
public MyClassWithDictionary()
{
Properties = new Dictionary<string, string>();
}
}
class NewtonsoftJsonConverter : JsonConverter<MyClass1>, ITransientDependency
{
public override void WriteJson(JsonWriter writer, MyClass1 value, JsonSerializer serializer)

Loading…
Cancel
Save