Description
Hi,
I'm not sure, if there's much that could be done about this issue, but implicit type deductions for numbers in JSON for modern C++ are problematic when a handler expects a float\double param and the RPC is using an integral param. I will try to explain with an example:
json foo (const float b) {
...
}
JsonRpc2Server rpc_handler;
rpc_handler.Add("foo", GetHandle(foo), {"bar"});
If foo
is invoked like this: {"method":"foo","params":{"bar":10}}
, then nlohmann would determine that 10
is an unsigned number and the dispatcher will throw (invalid parameter: must be float, but is unsigned integer for parameter "bar"
) when it tries to invoke the method.
The only workaround I've found so far is to setup foo
to expect a string, and then invoke it like this: {"method":"foo","params":{"bar":"10"}}
.
If anyone has other\better ideas, I'd be happy to hear those.
Thanks.