@@ -170,6 +170,10 @@ impl Params {
170170 serde_json::from_value(value)
171171 .map_err(|err| Error::invalid_params(format!("Invalid params: {}.", err)))
172172 }
173+
174+ pub fn is_none(&self) -> bool {
175+ self == &Params::None
176+ }
173177}
174178
175179impl From<Params> for Value {
@@ -187,7 +191,7 @@ impl From<Params> for Value {
187191pub struct MethodCall {
188192 pub jsonrpc: Option<Version>,
189193 pub method: String,
190− #[serde(default = "default_params")]
194+ #[serde(default = "default_params", skip_serializing_if = "Params::is_none")]
191195 pub params: Params,
192196 pub id: Id,
193197}
@@ -197,7 +201,7 @@ pub struct MethodCall {
197201pub struct Notification {
198202 pub jsonrpc: Option<Version>,
199203 pub method: String,
200− #[serde(default = "default_params")]
204+ #[serde(default = "default_params", skip_serializing_if = "Params::is_none")]
201205 pub params: Params,
202206}
203207
@@ -334,6 +338,33 @@ fn notification_serialize() {
334338 );
335339}
336340
341+#[test]
342+fn serialize_skip_none_params() {
343+ use serde_json;
344+
345+ let m = MethodCall {
346+ jsonrpc: Some(Version::V2),
347+ method: "shutdown".to_owned(),
348+ params: Params::None,
349+ id: Id::Num(1),
350+ };
351+
352+ let serialized = serde_json::to_string(&m).unwrap();
353+ assert_eq!(
354+ serialized,
355+ r#"{"jsonrpc":"2.0","method":"shutdown","id":1}"#
356+ );
357+
358+ let n = Notification {
359+ jsonrpc: Some(Version::V2),
360+ method: "exit".to_owned(),
361+ params: Params::None,
362+ };
363+
364+ let serialized = serde_json::to_string(&n).unwrap();
365+ assert_eq!(serialized, r#"{"jsonrpc":"2.0","method":"exit"}"#);
366+}
367+
337368#[test]
338369fn success_output_deserialize() {
339370 use serde_json;