Skip to content

RPC methods expecting floats\doubles could be called with an integral type which would throw an exception #18

Closed
@eniv

Description

@eniv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions