public override void Write(Utf8JsonWriter writer, DeltaAnnotated <T> value, JsonSerializerOptions options) { writer.WriteStartObject(); if (value.Data is IShaped shaped) { shaped.WriteInner(writer, shaped, options); WriteAnnotation(writer, value); } else if (value.Data is IAnnotated annotated) { annotated.WriteInner(writer, annotated, options); WriteAnnotation(writer, value); } else { WriteInner(_members, _reader, writer, value, options); } writer.WriteEndObject(); }
private static void WriteAnnotation(Utf8JsonWriter writer, DeltaAnnotated <T> value) { writer.WritePropertyName(DeltaLinkName); writer.WriteStringValue(value.DeltaLink); }
internal static void WriteInner(AccessorMembers members, IReadAccessor reader, Utf8JsonWriter writer, DeltaAnnotated <T> value, JsonSerializerOptions options) { if (value.Data != null) { foreach (var member in members) { if (!member.CanRead) { continue; } // key: var propertyName = options.PropertyNamingPolicy?.ConvertName(member.Name) ?? member.Name; writer.WritePropertyName(propertyName); // value (can be null): reader.TryGetValue(value.Data, member.Name, out var item); JsonSerializer.Serialize(writer, item, options); } } WriteAnnotation(writer, value); }