MongoExtensions / src / BsonExtensions / Converters / BsonDocumentJsonConverter.cs
Code · 19 lines · 596 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19using MongoDB.Bson;

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

namespace BsonExtensions.Converters;

public class BsonDocumentJsonConverter : JsonConverter<BsonDocument>
{
	public override BsonDocument Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		throw new NotImplementedException();
	}

	public override void Write(Utf8JsonWriter writer, BsonDocument bsonDocument, JsonSerializerOptions options)
	{
		writer.WriteRawValue(BsonJsonSerializer.ToJson(0, bsonDocument, options, BsonJsonSerializer.TypeSerializationEnum.None));
	}
}