Skip to content

Commit

Permalink
Merge pull request #7702 from abpframework/fix-7701
Browse files Browse the repository at this point in the history
System.Text.Json can't deserialize properties of EtoBase class
  • Loading branch information
hikalkan authored Feb 11, 2021
2 parents 2f64f74 + 1780bba commit 7a86980
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 7a86980

Please sign in to comment.