Apply changes from #11805 and #11806 to v9 (#11904)

* Apply changes from #11805 and #11806 to v9

* Update documentation and cleanup code styling
This commit is contained in:
Ronald Barendse
2022-01-26 12:22:05 +01:00
committed by GitHub
parent 72533d29c8
commit 4d4aff4c67
16 changed files with 159 additions and 150 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@@ -15,25 +15,20 @@ namespace Umbraco.Cms.Infrastructure.Serialization
{
new StringEnumConverter()
},
Formatting = Formatting.None
Formatting = Formatting.None,
NullValueHandling = NullValueHandling.Ignore
};
public string Serialize(object input)
{
return JsonConvert.SerializeObject(input, JsonSerializerSettings);
}
public T Deserialize<T>(string input)
{
return JsonConvert.DeserializeObject<T>(input, JsonSerializerSettings);
}
public string Serialize(object input) => JsonConvert.SerializeObject(input, JsonSerializerSettings);
public T Deserialize<T>(string input) => JsonConvert.DeserializeObject<T>(input, JsonSerializerSettings);
public T DeserializeSubset<T>(string input, string key)
{
if (key == null) throw new ArgumentNullException(nameof(key));
var root = JsonConvert.DeserializeObject<JObject>(input);
var jToken = root.SelectToken(key);
var root = Deserialize<JObject>(input);
var jToken = root?.SelectToken(key);
return jToken switch
{