Skip to content

Commit

Permalink
Fixes #7701: System.Text.Json can't deserialize properties of EtoBase…
Browse files Browse the repository at this point in the history
… class.
  • Loading branch information
hikalkan committed Feb 11, 2021
1 parent 2f64f74 commit 1780bba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ public void SystemTextJsonSerialize_Test()

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
{
Expand All @@ -83,6 +100,16 @@ public class MyClass3
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)
Expand Down

0 comments on commit 1780bba

Please sign in to comment.