diff --git a/src/Im/Dtos/PostContent.cs b/src/Im/Dtos/PostContent.cs index 2a255dd4..8838d24e 100644 --- a/src/Im/Dtos/PostContent.cs +++ b/src/Im/Dtos/PostContent.cs @@ -11,12 +11,16 @@ // // 富文本消息 // ************************************************************************ + +using System.Text.Json; + namespace FeishuNetSdk.Im.Dtos { /// /// 富文本消息 /// /// 富文本消息。post content格式请参见发送消息Content + [JsonConverter(typeof(PostContentJsonConverter))] public record PostContent([property: JsonPropertyName("post")] I18nLanguage Post = default!) : MessageContent("post") { @@ -57,4 +61,18 @@ public record PostLanguage public object[][] Content { get; set; } = Array.Empty(); } } + + internal class PostContentJsonConverter : JsonConverter + { + public override PostContent Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var postLanguage = JsonSerializer.Deserialize>(ref reader, options); + return new PostContent(postLanguage); + } + + public override void Write(Utf8JsonWriter writer, PostContent value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value.Post, options); + } + } }