Skip to content

Deserializing to a struct as shown on the project homepage throws compile time errors #2665

@kitattyor

Description

@kitattyor

Can you provide a small but working code example?

Code:

static void throwaway2() {
  // a simple struct to model a person
  struct person {
    std::string name;
    std::string address;
    int age;
  };
  // create a person
  person p{"Ned Flanders", "744 Evergreen Terrace", 60};

  // conversion: person -> json
  auto j = R"({
	"name": "Ned Flanders",
	"address": "744 Evergreen Terrace",
	"age": 60
		})"_json;

  std::cout << j << std::endl;

  auto p2 = j.get<person>(); // Error here 

  assert(p == p2);
}

Error:

error C2672: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::get': no matching overloaded function found 

error C2783: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>> nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::get(void) const': could not deduce template argument for '__formal' 

[build] D:\Libs\vcpkg\installed\x64-windows\include\nlohmann/json.hpp(2848): message : see declaration of 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::get' 
  • Compiler: ___ Visual Studio 2017 x64
  • Operating system: ___ Windows 10

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions