LootDumpProcessor/Serializers/Json/NetJsonSerializer.cs
chomp 6e4c7abf73 dump-processor-cleanup (#6)
Co-authored-by: Alex <alex@dm-me-for-questions.com>
Reviewed-on: SPT-AKI/LootDumpProcessor#6
2024-04-16 18:29:40 +00:00

29 lines
767 B
C#

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