Skip to content

Custom JSON Parsers Not Detected #10

Closed
@freesurfer-rge

Description

@freesurfer-rge

I seem to be unable to successfully use methods whose arguments are types such as enum classes, where I have used nlohmann::json to provide serialisation and deserialisation routines. The method successfully binds, but when I invoke it using curl, there is an error response of invalid parameter: must be object, but is string for parameter \"e\"

The attached zip file contains a repro case. The enum itself is:

 enum class MyEnum { Zero, One, Two };

with serialisation provided by NLOHMANN_JSON_SERIALIZE_ENUM. There are then two methods which I'm attempting to call:

  int MyService::OptionOne( MyEnum e ) {
    std::cout << __FUNCTION__ << std::endl;
    return static_cast<int>(e);
  }

  int MyService::OptionTwo( std::string s ) {
    std::cout << __FUNCTION__ << std::endl;
    nlohmann::json j(s);

    MyEnum e = j.get<MyEnum>();

    return static_cast<int>(e);
  }

I can invoke the second via:

curl http://localhost:8483/jsonrpc -H "Content-Type application/json" --data '{ "method":"OptionTwo", "params":{"s":"One"}, "id":10, "jsonrpc": "2.0" }'

However, when I try to call the first:

curl http://localhost:8483/jsonrpc -H "Content-Type application/json" --data '{ "method":"OptionOne", "params":{"e":"One"}, "id":10, "jsonrpc": "2.0" }'

I see the error noted above.

jsonrpccxxissue.zip

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