Skip to content

Commit

Permalink
let version be omitted when deserializing a request
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges760 authored and DoumanAsh committed Aug 28, 2023
1 parent 1f0ad06 commit 8e1f975
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::id::Id;
#[serde(deny_unknown_fields)]
pub struct Request<P, T=StrBuf> {
///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
///
Expand Down
13 changes: 13 additions & 0 deletions tests/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8e1f975

Please sign in to comment.