Introduce IContentNestedDataSerializer to allow injecting a custom serializer for nucache

This commit is contained in:
nzdev
2020-07-01 17:19:56 +12:00
parent 90a9ce4c5d
commit 578e1317a0
14 changed files with 245 additions and 28 deletions

View File

@@ -0,0 +1,31 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Serialization;
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
internal class JsonContentNestedDataSerializer : IContentNestedDataSerializer
{
public ContentNestedData Deserialize(string data)
{
// by default JsonConvert will deserialize our numeric values as Int64
// which is bad, because they were Int32 in the database - take care
var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new ForceInt32Converter() }
};
return JsonConvert.DeserializeObject<ContentNestedData>(data, settings);
}
public string Serialize(ContentNestedData nestedData)
{
return JsonConvert.SerializeObject(nestedData);
}
}
}