LootDumpProcessor/Serializers/Json/NewtonsoftJsonSerializer.cs

28 lines
701 B
C#
Raw Permalink Normal View History

using LootDumpProcessor.Serializers.Json.Converters;
2023-08-12 19:08:38 +01:00
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace LootDumpProcessor.Serializers.Json;
public class NewtonsoftJsonSerializer : IJsonSerializer
{
private static readonly JsonSerializerSettings _settings = new()
2023-08-12 19:08:38 +01:00
{
Converters =
{
new NewtonsoftJsonKeyConverter(),
new StringEnumConverter(),
new NewtonsoftDateTimeConverter()
2023-08-12 19:08:38 +01:00
}
};
public string Serialize<T>(T obj)
{
return JsonConvert.SerializeObject(obj, _settings);
}
public T? Deserialize<T>(string obj)
2023-08-12 19:08:38 +01:00
{
return JsonConvert.DeserializeObject<T>(obj, _settings);
}
}