-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Labels
state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updatedthe issue has not been updated in a while and will be closed automatically soon unless it is updated
Description
Making to_json() and from_json() for all classes in my object model is a chore.
I want to create a macro that would generate bodies for these functions. I saw some clues how to make it, but my knowledge of C++ is not good enough to implement it.
I want to be able to write something like this:
class MyClass
{
...
JsonVar(int, intvar)
JsonVar(string, stingvar)
...
}
void to_json(json& j, const MyClass& p) {
JsonTo(MyClass)
... //some extra serialization
}
void from_json(const json& j, MyClass& p) {
JsonFrom(MyClass)
... //some extra deserialization
}and get
class MyClass
{
...
int intvar;
string stringvar;
...
}
void to_json(json& j, const MyClass& p) {
j = json{ { "intvar", p.intvar},
{ "stringvar", p.stringvar} };
... //some extra serialization
}
void from_json(const json& j, MyClass& p) {
p.intvar= j.at("intvar").get<int>();
p.stringvar= j.at("stringvar").get<string>();
... //some extra deserialization
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updatedthe issue has not been updated in a while and will be closed automatically soon unless it is updated