mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 21:39:46 +00:00
Defined a JSON converter for the EncryptedText type
This commit is contained in:
parent
a95cfc5ac8
commit
273376ad97
@ -1,7 +1,9 @@
|
|||||||
using System.Security;
|
using System.Security;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace AIStudio.Tools;
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
|
[JsonConverter(typeof(EncryptedTextJsonConverter))]
|
||||||
public readonly record struct EncryptedText(string EncryptedData)
|
public readonly record struct EncryptedText(string EncryptedData)
|
||||||
{
|
{
|
||||||
public EncryptedText() : this(string.Empty)
|
public EncryptedText() : this(string.Empty)
|
||||||
|
27
app/MindWork AI Studio/Tools/EncryptedTextJsonConverter.cs
Normal file
27
app/MindWork AI Studio/Tools/EncryptedTextJsonConverter.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
|
public sealed class EncryptedTextJsonConverter : JsonConverter<EncryptedText>
|
||||||
|
{
|
||||||
|
#region Overrides of JsonConverter<EncryptedText>
|
||||||
|
|
||||||
|
public override EncryptedText Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (reader.TokenType is JsonTokenType.String)
|
||||||
|
{
|
||||||
|
var value = reader.GetString()!;
|
||||||
|
return new EncryptedText(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new JsonException($"Unexpected token type when parsing EncryptedText. Expected {JsonTokenType.String}, but got {reader.TokenType}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, EncryptedText value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteStringValue(value.EncryptedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user