LootDumpProcessor/Serializers/Json/NetJsonSerializer.cs

29 lines
767 B
C#
Raw Normal View History

using System.Text.Json;
2023-08-12 19:08:38 +01:00
using System.Text.Json.Serialization;
using LootDumpProcessor.Serializers.Json.Converters;
2023-08-12 19:08:38 +01:00
namespace LootDumpProcessor.Serializers.Json;
public class NetJsonSerializer : IJsonSerializer
{
private static JsonSerializerOptions _serializeOptions = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters =
{
new NetJsonKeyConverter(),
new JsonStringEnumConverter(),
new NetDateTimeConverter()
2023-08-12 19:08:38 +01:00
}
};
2023-08-12 19:08:38 +01:00
public string Serialize<T>(T obj)
{
return JsonSerializer.Serialize(obj, _serializeOptions);
}
public T? Deserialize<T>(string obj)
2023-08-12 19:08:38 +01:00
{
return JsonSerializer.Deserialize<T>(obj, _serializeOptions);
}
}