Browse Source

Merge pull request #7702 from abpframework/fix-7701

System.Text.Json can't deserialize properties of EtoBase class
pull/7703/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
7a8698020c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/EtoBase.cs
  2. 27
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpHybridJsonSerializer_Tests.cs

4
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<string, object> Properties { get; }
public Dictionary<string, string> Properties { get; set; }
protected EtoBase()
{
Properties = new Dictionary<string, object>();
Properties = new Dictionary<string, string>();
}
}
}

27
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<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