Skip to content

converting json to vector of type with templated constructor #924

Description

@dvirtz

Bug Report

The following code fails to compile when uncommenting line 16:

#include <nlohmann/json.hpp>

namespace nl = nlohmann;

struct S {
  S() = default;
  template<typename T> S(const T& t) {}
};

void from_json(const nl::json& j, S& s) {
}

int main() {
  nl::json j;
  auto s = j.get<S>();
  //auto v = j.get<std::vector<S>>();
};

The error I get is

json.hpp(1360): error C2338: could not find from_json() method in T's namespace

The cause seems to stem from the check for std::is_convertible<BasicJsonType, typename CompatibleArrayType::value_type>::value on void from_json(const BasicJsonType& j, CompatibleArrayType& arr).

Since you do not convert directly from json to the array value but call get() I think this check can be changed to allow this to compile.

Compiled on VS 15.6.0 preview 2.0
Library version 3.0.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind: bugsolution: proposed fixa fix for the issue has been proposed and waits for confirmation

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions