2024-04-16 18:29:40 +00:00
|
|
|
using System.Text.Json;
|
2023-08-12 19:08:38 +01:00
|
|
|
using System.Text.Json.Serialization;
|
2023-08-13 17:26:49 +01:00
|
|
|
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(),
|
2023-08-13 17:26:49 +01:00
|
|
|
new JsonStringEnumConverter(),
|
|
|
|
new NetDateTimeConverter()
|
2023-08-12 19:08:38 +01:00
|
|
|
}
|
|
|
|
};
|
2023-08-13 17:26:49 +01:00
|
|
|
|
2023-08-12 19:08:38 +01:00
|
|
|
public string Serialize<T>(T obj)
|
|
|
|
{
|
|
|
|
return JsonSerializer.Serialize(obj, _serializeOptions);
|
|
|
|
}
|
|
|
|
|
2024-04-16 18:29:40 +00:00
|
|
|
public T? Deserialize<T>(string obj)
|
2023-08-12 19:08:38 +01:00
|
|
|
{
|
|
|
|
return JsonSerializer.Deserialize<T>(obj, _serializeOptions);
|
|
|
|
}
|
|
|
|
}
|