因此,我偶然发现了一篇文章,该文章演示了如何
Jsondocument在新
System.Text.Json名称空间中使用该对象,这是Fluent
API的第二大优点。这是解决这个问题的方法。
BookConverter.Write()方法:
public override void Write(Utf8JsonWriter writer, Book value, JsonSerializerOptions options){ writer.WriteStartObject(); using (Jsondocument document = Jsondocument.Parse(JsonSerializer.Serialize(value))) { foreach (var property in document.RootElement.EnumerateObject()) { if (property.Name != "Author") property.WriteTo(writer); } } writer.WriteEndObject();}


