using System.Text.Json;
using System.Text.Json.Serialization;

namespace JSMR.Infrastructure.Integrations.DLSite.Serialization;

public sealed class DictionaryConverter<TKey, TValue> : JsonConverter<Dictionary<TKey, TValue>> where TKey : notnull
{
    public override Dictionary<TKey, TValue>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        => JsonSerializer.Deserialize<Dictionary<TKey, TValue>>(ref reader, options);

    public override void Write(Utf8JsonWriter writer, Dictionary<TKey, TValue> value, JsonSerializerOptions options)
        => JsonSerializer.Serialize(writer, value, options);
}