Skip to content

std::array when a param item is converted to object not array #52

@bjorn-jaes

Description

@bjorn-jaes

Same as issue #49 when using std::array in a jsonrpc message as a child of params it gets interpreted as a json object instead of array. Arrays works as a return type, and nested inside another child object of param object but when part of params it causes a type error.

{
  "id": 0,
  "jsonrpc": "2.0",
  "method": "set-camera-location",
  "params": {
    "index": 0,
    "location": [
      10.0,
      20.0,
      30.0
    ]
  }
}

Given this function:

bool method(const int index, const std::array<double, 3>& location);

This causes:

unknown file: Failure
C++ exception with description "-32602: invalid parameter: must be object, but is array for parameter "location"" thrown in the test body.

Fix is to add the following to typemapper.hpp

#include <array>

template <typename T, std::size_t N>
constexpr json::value_t GetType(type<std::array<T, N>>) {
  return json::value_t::array;
}

I know that @cinemast mentioned that they wont add more built in custom mappings, but I thought it would be useful to point out the issue if someone else also got stuck wondering why their methods are not working.

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