Skip to content

Commit 86d7a89

Browse files
authored
Merge pull request #43 from ethcore/fix-jsonrpc-omitted
Don't serialize version field if it is not set explicitly
2 parents d54efce + 2ecfb97 commit 86d7a89

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/src/io.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn write_response(response: Response) -> String {
287287
mod tests {
288288
use futures::{self, Future};
289289
use types::{Value};
290-
use super::{IoHandler};
290+
use super::{IoHandler, Compatibility};
291291

292292
#[test]
293293
fn test_io_handler() {
@@ -303,6 +303,20 @@ mod tests {
303303
assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
304304
}
305305

306+
#[test]
307+
fn test_io_handler_1dot0() {
308+
let mut io = IoHandler::with_compatibility(Compatibility::Both);
309+
310+
io.add_method("say_hello", |_| {
311+
Ok(Value::String("hello".to_string()))
312+
});
313+
314+
let request = r#"{"method": "say_hello", "params": [42, 23], "id": 1}"#;
315+
let response = r#"{"result":"hello","id":1}"#;
316+
317+
assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
318+
}
319+
306320
#[test]
307321
fn test_async_io_handler() {
308322
let mut io = IoHandler::new();

core/src/types/response.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::{Id, Value, Error, ErrorCode, Version};
88
#[derive(Debug, PartialEq, Serialize, Deserialize)]
99
pub struct Success {
1010
/// Protocol version
11+
#[serde(skip_serializing_if = "Option::is_none")]
1112
pub jsonrpc: Option<Version>,
1213
/// Result
1314
pub result: Value,

0 commit comments

Comments
 (0)