Skip to content

Invalid type error when calling a function where one of the types is Json. #51

Open
@phelter

Description

@phelter

Have a call that is defined in the following manner:

using Json = nlohmann::json;
using JsonPointer = nlohmann::json_pointer;

Json SomeStruct::setProperty(const JsonPointer &pointer, const Json &value)
{
   Json j;
   to_json(j, *this);
   j[pointer] = value;
   from_json(j, *this);
}

It's used in a manner to allow independent values within a class/struct that can be converted to_json(json, SomeStruct) and allow the property to be changed. - So using the Json type as a variant of what is allowed and then converting and reconverting the values to allow the API to identify a single value to change.

The problem I have is when I do the following:

        const std::function<Json(const std::string &, const Json &)> setPropertyFn = [this](const std ::string &pointer,
                                                                                            const Json &value) {
            auto result = m_myStruct->setProperty(JsonPointer(pointer), value);
        };
        addRpc("struct.setProperty", GetHandle(setPropertyFn), {"pointer", "value"});

When I send the following for example:

{"id":8,"jsonrpc":"2.0","method":"struct.setProperty","params":["/type/subtype/subtype2/value",20]}

I get the return of:

{"error":{"code":-32602,"message":"invalid parameter: must be object, but is unsigned integer for parameter \"value\""},"id":8,"jsonrpc":"2.0"}

But there should be no comparison needed as the param_type is already json.

Suggest changing:

template<typename T>
inline void check_param_type...
  • inline void check_param_type(...) { /* No type checks just pass it along */}
  • rest operate as expected.

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