mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-07-28 17:42:57 +00:00
implemented a json converter to parse metadata
This commit is contained in:
parent
ee314ada04
commit
2ce863ebd6
@ -0,0 +1,51 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace AIStudio.Settings.DataModel;
|
||||||
|
|
||||||
|
public class MetadataJsonConverter : JsonConverter<Metadata>
|
||||||
|
{
|
||||||
|
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<TextMetadata>(root.GetRawText(), options);
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("Pdf", out _))
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<PdfMetadata>(root.GetRawText(), options);
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("Spreadsheet", out _))
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<SpreadsheetMetadata>(root.GetRawText(), options);
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("Presentation", out _))
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<PresentationMetadata>(root.GetRawText(), options);
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("Image", out _))
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<ImageMetadata>(root.GetRawText(), options);
|
||||||
|
}
|
||||||
|
else if (root.TryGetProperty("Document", out _))
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<DocumentMetadata>(root.GetRawText(), options);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Unbekannter Typ
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, Metadata value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user