use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplyInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_id: Option<String>,
pub content: ReplyContent,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub create_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub update_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub extra: Option<ReplyExtra>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplyContent {
pub elements: Vec<ReplyElement>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplyElement {
#[serde(rename = "type")]
pub r#type: String,
pub text_run: Option<TextRun>,
pub docs_link: Option<DocsLink>,
pub person: Option<Person>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplyExtra {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub image_list: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextRun {
pub text: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocsLink {
pub url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Person {
pub user_id: String,
}
#[cfg(test)]
mod tests {
use serde_json;
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
assert_eq!(value["field"], "data");
}
}