mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
24 lines
585 B
C#
24 lines
585 B
C#
using System.Text.Json;
|
|
using NadekoBot.Common.JsonConverters;
|
|
|
|
namespace NadekoBot.Common;
|
|
|
|
public class JsonSeria : ISeria
|
|
{
|
|
private readonly JsonSerializerOptions _serializerOptions = new()
|
|
{
|
|
Converters = { new Rgba32Converter(), new CultureInfoConverter(), }
|
|
};
|
|
|
|
public byte[] Serialize<T>(T data)
|
|
=> JsonSerializer.SerializeToUtf8Bytes(data, _serializerOptions);
|
|
|
|
public T? Deserialize<T>(byte[]? data)
|
|
{
|
|
if (data is null)
|
|
return default;
|
|
|
|
return JsonSerializer.Deserialize<T>(data, _serializerOptions);
|
|
}
|
|
}
|