using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using MongoDB.Bson;
namespace Dpz.Core.Infrastructure;
public class ObjectIdConverter:JsonConverter<ObjectId>
{
public override ObjectId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (ObjectId.TryParse(reader.GetString(),out var oid))
{
return oid;
}
throw new JsonException();
}
public override void Write(Utf8JsonWriter writer, ObjectId value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}