#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
#endregion
namespace Lumina.Presentation.Api.IntegrationTests.Common.Converters;
///
/// Custom JSON converter for readonly collections.
///
[ExcludeFromCodeCoverage]
public class ReadOnlySetConverter : JsonConverter>
{
///
/// Reads and converts JSON to a object.
///
/// The JSON reader.
/// The type of the object to convert.
/// The serializer options.
/// The converted readonly collection.
public override IReadOnlySet Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
HashSet? list = JsonSerializer.Deserialize>(ref reader, options);
return list ?? [];
}
///
/// Writes a readonly collection object to JSON. This method is not implemented.
///
/// The JSON writer.
/// The object to write.
/// The serializer options.
public override void Write(Utf8JsonWriter writer, IReadOnlySet value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value.ToList(), options);
}
}