2019-11-07 21:28:56 +11:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2019-11-14 16:19:24 +11:00
|
|
|
|
using Newtonsoft.Json.Converters;
|
2019-11-07 21:28:56 +11:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Serialization
|
|
|
|
|
|
{
|
|
|
|
|
|
public class JsonNetSerializer : IJsonSerializer
|
|
|
|
|
|
{
|
2019-11-14 16:19:24 +11:00
|
|
|
|
private static readonly JsonConverter[] _defaultConverters = new JsonConverter[]
|
|
|
|
|
|
{
|
|
|
|
|
|
new StringEnumConverter()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-11-07 21:28:56 +11:00
|
|
|
|
public string Serialize(object input)
|
|
|
|
|
|
{
|
2019-11-14 16:19:24 +11:00
|
|
|
|
return JsonConvert.SerializeObject(input, _defaultConverters);
|
2019-11-07 21:28:56 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T Deserialize<T>(string input)
|
|
|
|
|
|
{
|
2019-11-14 16:19:24 +11:00
|
|
|
|
return JsonConvert.DeserializeObject<T>(input, _defaultConverters);
|
2019-11-07 21:28:56 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|