You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following code Newtonsoft.Json correctly deserializes but System.Text.Json doesn't with the dictionary being empty. If the IDictionary<string, string> property has a setter, the deserialization works. However, I don't control the class that requires serialization/deserialization and it includes IDictionary<string, string> properties with getters only.
`
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text.Json;
namespace TestConsoleApp
{
class Test
{
public IDictionary<string, string> Items { get; } = new Dictionary<string, string>();
}
class Program
{
static void Main(string[] args)
{
var test = new Test();
test.Items["a"] = "1";
test.Items["b"] = "2";
var json = System.Text.Json.JsonSerializer.Serialize(test);
// Dictionary is empty.
var test2 = System.Text.Json.JsonSerializer.Deserialize<Test>(json);
// Correctly deserialized.
var test3 = JsonConvert.DeserializeObject<Test>(json);
}
}
}
`
The text was updated successfully, but these errors were encountered:
In the following code Newtonsoft.Json correctly deserializes but System.Text.Json doesn't with the dictionary being empty. If the IDictionary<string, string> property has a setter, the deserialization works. However, I don't control the class that requires serialization/deserialization and it includes IDictionary<string, string> properties with getters only.
`
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text.Json;
namespace TestConsoleApp
{
class Test
{
public IDictionary<string, string> Items { get; } = new Dictionary<string, string>();
}
}
`
The text was updated successfully, but these errors were encountered: