using System.Text.Json; using System.Text.Json.Serialization; namespace AIStudio.Settings.DataModel; public class MetadataJsonConverter : JsonConverter { public override Metadata? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using (var jsonDoc = JsonDocument.ParseValue(ref reader)) { var root = jsonDoc.RootElement; if (root.TryGetProperty("Text", out _)) { return JsonSerializer.Deserialize(root.GetRawText(), options); } else if (root.TryGetProperty("Pdf", out _)) { return JsonSerializer.Deserialize(root.GetRawText(), options); } else if (root.TryGetProperty("Spreadsheet", out _)) { return JsonSerializer.Deserialize(root.GetRawText(), options); } else if (root.TryGetProperty("Presentation", out _)) { return JsonSerializer.Deserialize(root.GetRawText(), options); } else if (root.TryGetProperty("Image", out _)) { return JsonSerializer.Deserialize(root.GetRawText(), options); } else if (root.TryGetProperty("Document", out _)) { return JsonSerializer.Deserialize(root.GetRawText(), options); } else { // Unbekannter Typ return null; } } } public override void Write(Utf8JsonWriter writer, Metadata value, JsonSerializerOptions options) { throw new NotImplementedException(); } }