BotSharp/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/RichContentJsonConverter .cs
2024-05-08 11:47:21 -05:00

19 lines
674 B
C#

using System.Text.Json;
namespace BotSharp.Abstraction.Messaging.JsonConverters;
public class RichContentJsonConverter : JsonConverter<IRichMessage>
{
public override IRichMessage? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var jsonDoc = JsonDocument.ParseValue(ref reader);
var root = jsonDoc.RootElement;
var res = BotSharpMessageParser.ParseRichMessage(root, options);
return res;
}
public override void Write(Utf8JsonWriter writer, IRichMessage value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, value.GetType(), options);
}
}