2020-07-01 17:19:56 +12:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2020-07-03 12:11:05 +10:00
|
|
|
|
using System.Reflection.Emit;
|
2020-07-01 17:19:56 +12:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Umbraco.Core.Serialization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
|
|
|
|
|
{
|
2020-07-03 12:11:05 +10:00
|
|
|
|
|
2020-07-01 17:19:56 +12:00
|
|
|
|
internal class JsonContentNestedDataSerializer : IContentNestedDataSerializer
|
|
|
|
|
|
{
|
2020-08-26 15:57:13 +10:00
|
|
|
|
public ContentNestedData Deserialize(int contentTypeId, string data)
|
2020-07-01 17:19:56 +12:00
|
|
|
|
{
|
|
|
|
|
|
// 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
|
|
|
|
|
|
{
|
2020-07-03 12:11:05 +10:00
|
|
|
|
Converters = new List<JsonConverter> { new ForceInt32Converter() },
|
|
|
|
|
|
|
|
|
|
|
|
// Explicitly specify date handling so that it's consistent and follows the same date handling as MessagePack
|
|
|
|
|
|
DateParseHandling = DateParseHandling.DateTime,
|
|
|
|
|
|
DateFormatHandling = DateFormatHandling.IsoDateFormat,
|
|
|
|
|
|
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
|
|
|
|
|
DateFormatString = "o"
|
2020-07-01 17:19:56 +12:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return JsonConvert.DeserializeObject<ContentNestedData>(data, settings);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-26 15:57:13 +10:00
|
|
|
|
public string Serialize(int contentTypeId, ContentNestedData nestedData)
|
2020-07-01 17:19:56 +12:00
|
|
|
|
{
|
2020-07-03 12:11:05 +10:00
|
|
|
|
// note that numeric values (which are Int32) are serialized without their
|
|
|
|
|
|
// type (eg "value":1234) and JsonConvert by default deserializes them as Int64
|
|
|
|
|
|
|
2020-07-01 17:19:56 +12:00
|
|
|
|
return JsonConvert.SerializeObject(nestedData);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|