LootDumpProcessor/Serializers/Json/NetJsonSerializer.cs
Refringe 0719a7bfdd
Resolves ArgumentException when processing 0.15.5 loot
Resolves the following exception:

System.ArgumentException: .NET number values such as positive and negative infinity cannot be written as valid JSON. To make it work when using 'JsonSerializer', consider specifying 'JsonNumberHandling.AllowNamedFloatingPointLiterals'
2024-10-31 22:42:26 -04:00

31 lines
845 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,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
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);
}
}