2024-08-03 20:17:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Questionable.Model.Questing.Converter;
|
|
|
|
|
|
2024-08-04 14:03:23 +00:00
|
|
|
|
public sealed class ElementIdConverter : JsonConverter<ElementId>
|
2024-08-03 20:17:18 +00:00
|
|
|
|
{
|
|
|
|
|
public override ElementId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
|
|
|
{
|
2024-08-04 14:03:23 +00:00
|
|
|
|
if (reader.TokenType == JsonTokenType.Number)
|
|
|
|
|
return new QuestId(reader.GetUInt16());
|
|
|
|
|
else
|
|
|
|
|
return ElementId.FromString(reader.GetString() ?? throw new JsonException());
|
2024-08-03 20:17:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Write(Utf8JsonWriter writer, ElementId value, JsonSerializerOptions options)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|