-
Notifications
You must be signed in to change notification settings - Fork 270
Open
Description
when I use this lib to make a call to aria2c system.listMethods, I find the params
serialized to null
even when the method defined without args.
use jsonrpc_core_client::transports::http;
use jsonrpc_core::Result;
use jsonrpc_derive::rpc;
/// Rpc trait
#[rpc]
pub trait Rpc {
/// Returns a protocol version
#[rpc(name = "system.listMethods")]
fn list_methods(&self) -> Result<Vec<String>>;
}
#[tokio::main]
async fn main() -> Result<()>{
let client = http::connect::<gen_client::Client>("http://127.0.0.1:6800/jsonrpc").await.unwrap();
println!("{:?}", client.list_methods().await.unwrap());
Ok(())
}
the code will send {"jsonrpc":"2.0","method":"system.listMethods","params":null,"id":0}
to aria2 and then got HTTPError: HTTP Error 500: Internal Server Error
if skip the params
when it is None
, things go right.
/// Represents jsonrpc request which is a method call.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct MethodCall {
/// A String specifying the version of the JSON-RPC protocol.
pub jsonrpc: Option<Version>,
/// A String containing the name of the method to be invoked.
pub method: String,
/// A Structured value that holds the parameter values to be used
/// during the invocation of the method. This member MAY be omitted.
#[serde(default = "default_params")]
#[serde(skip_serializing_if="omit_params")]
pub params: Params,
/// An identifier established by the Client that MUST contain a String,
/// Number, or NULL value if included. If it is not included it is assumed
/// to be a notification.
pub id: Id,
}
fn omit_params(param: &Params) -> bool {
&Params::None == param
}
so could we add this annotation to skip serializing when it is None
?
Metadata
Metadata
Assignees
Labels
No labels