use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JsonRpcNotification {
pub jsonrpc: String,
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<serde_json::Value>,
}
pub mod notification_methods {
pub const RESOURCES_UPDATED: &str = "notifications/resources/updated";
pub const RESOURCES_LIST_CHANGED: &str = "notifications/resources/list_changed";
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_notification_serialize() {
let notif = JsonRpcNotification {
jsonrpc: "2.0".to_string(),
method: "notifications/initialized".to_string(),
params: None,
};
let json = serde_json::to_string(¬if).unwrap();
assert!(json.contains("\"method\":\"notifications/initialized\""));
assert!(!json.contains("\"id\""));
assert!(!json.contains("\"params\""));
}
#[test]
fn test_notification_no_id() {
let json = r#"{"jsonrpc":"2.0","method":"notifications/initialized"}"#;
let notif: JsonRpcNotification = serde_json::from_str(json).unwrap();
assert_eq!(notif.jsonrpc, "2.0");
assert_eq!(notif.method, "notifications/initialized");
assert_eq!(notif.params, None);
}
}