From 8e1f97554d934aa6f80b8cb9d8d2641e8b8d312b Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Sun, 27 Aug 2023 19:01:39 +0200 Subject: [PATCH] let version be omitted when deserializing a request --- src/request.rs | 1 + tests/request.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/request.rs b/src/request.rs index ae4ff19..51cd0da 100644 --- a/src/request.rs +++ b/src/request.rs @@ -19,6 +19,7 @@ use crate::id::Id; #[serde(deny_unknown_fields)] pub struct Request { ///A String specifying the version of the JSON-RPC protocol. + #[serde(default)] pub jsonrpc: Version, ///A String containing the name of the method to be invoked /// diff --git a/tests/request.rs b/tests/request.rs index f3c12ff..fe615dc 100644 --- a/tests/request.rs +++ b/tests/request.rs @@ -58,6 +58,19 @@ fn notification_deserialize() { assert!(notification.is_notification()); assert_eq!(expected, notification); + + let text = r#"{"method":"update"}"#; + let notification: Request = serde_json::from_str(text).unwrap(); + + let expected = Request { + jsonrpc: Version::V2, + method: "update".try_into().unwrap(), + params: None, + id: None, + }; + + assert!(notification.is_notification()); + assert_eq!(expected, notification); } #[test]