From 1780bba7648a9f7a2929f4acda284204caf180cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 11 Feb 2021 22:06:33 +0300 Subject: [PATCH] Fixes #7701: System.Text.Json can't deserialize properties of EtoBase class. --- .../Entities/Events/Distributed/EtoBase.cs | 4 +-- .../Abp/Json/AbpHybridJsonSerializer_Tests.cs | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/EtoBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/EtoBase.cs index f574240dc8..c877dccc58 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/EtoBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/EtoBase.cs @@ -6,11 +6,11 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed [Serializable] public abstract class EtoBase { - public Dictionary Properties { get; } + public Dictionary Properties { get; set; } protected EtoBase() { - Properties = new Dictionary(); + Properties = new Dictionary(); } } } \ No newline at end of file diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpHybridJsonSerializer_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpHybridJsonSerializer_Tests.cs index eb44e51820..f719eb68f8 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpHybridJsonSerializer_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpHybridJsonSerializer_Tests.cs @@ -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(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 Properties { get; set; } + + public MyClassWithDictionary() + { + Properties = new Dictionary(); + } + } + class NewtonsoftJsonConverter : JsonConverter, ITransientDependency { public override void WriteJson(JsonWriter writer, MyClass1 value, JsonSerializer serializer)