Skip to content

Custom type registration : instrusive API #2175

@pfeatherstone

Description

@pfeatherstone

Currently, the API for registering custom types is as follows:

using nlohmann::json;

namespace ns {
    void to_json(json& j, const person& p) {
        j = json{{"name", p.name}, {"address", p.address}, {"age", p.age}};
    }

    void from_json(const json& j, person& p) {
        j.at("name").get_to(p.name);
        j.at("address").get_to(p.address);
        j.at("age").get_to(p.age);
    }

It would be great if there was a MACRO-style registration a bit like what msgpack-c uses:

struct person 
{
   std::string name;
   std::string address;
   int age;
   MSGPACK_DEFINE_MAP(name, address, age);
};

or yas:

struct   person
{
   std::string name;
   std::string address;
   int age;
    YAS_DEFINE_STRUCT_SERIALIZE("person", name, address, age);
};

or

struct   person
{
   std::string name;
   std::string address;
   int age;
};
YAS_DEFINE_INTRUSIVE_SERIALIZE("person", name, address, age);

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions