I want to move completely to .NET Core so I need to use System.Text.Json instead of Newtonsoft.Json.
How can I write this code in the System.Text.Json?
private readonly JsonSerializer _serializer;
_serializer = JsonSerializer.Create(new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
});
private JObject _jsonSettings;
protected override void LoadSection(string sectionName, object section)
{
var jsonSection = _jsonSettings[sectionName];
if (jsonSection != null)
{
using (var reader = jsonSection.CreateReader())
{
_serializer.Populate(reader, section);
}
}
}
protected override void SaveSection(string sectionName, object section)
{
var settings = _jsonSettings ?? new JObject();
settings[sectionName] = JObject.FromObject(section);
_jsonSettings = settings;
}
protected override void LoadDefaults()
{
_jsonSettings = new JObject();
}
private void LoadFromJson(string json)
{
_jsonSettings = JObject.Parse(json);
}