// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Newtonsoft.Json;
namespace Admin.NET.Core;
///
/// 自定义序列化提供器 Newtonsoft.Json 实现
///
public class NewtonsoftJsonSerializerProvider : IJsonSerializerProvider, ISingleton
{
///
/// 序列化对象
///
///
///
///
public string Serialize(object value, object jsonSerializerOptions = null)
{
return JsonConvert.SerializeObject(value, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);
}
///
/// 反序列化字符串
///
///
///
///
///
public T Deserialize(string json, object jsonSerializerOptions = null)
{
return JsonConvert.DeserializeObject(json, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);
}
///
/// 反序列化字符串
///
///
///
///
///
public object Deserialize(string json, Type returnType, object jsonSerializerOptions = null)
{
return JsonConvert.DeserializeObject(json, returnType, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);
}
///
/// 返回读取全局配置的 JSON 选项
///
///
public object GetSerializerOptions()
{
return App.GetOptions()?.SerializerSettings;
}
}