json
json copied to clipboard
I want the data field to be empty serialized and deserialized to each other
Description
class Data{
public:
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Data)
};
class test{
public:
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(test,cmd,data)
std::string cmd;
Data data;
};
Reproduction steps
std::string str = "{\n"
" \"cmd\": \"TtsPlay\", \n"
" \"data\": { }\n"
"}";
json js = json::parse(str);
test t = js;
js = t;
std::cout << js.dump() << std::endl;
Expected vs. actual results
I want the data field to be empty serialized and deserialized to each other
Minimal code example
No response
Error messages
error: expected unqualified-id before ‘;’ token
2733 | #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
Compiler and operating system
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
Library version
JSON for Modern C++ version 3.11.2
Validation
- [ ] The bug also occurs if the latest version from the
developbranch is used. - [ ] I can successfully compile and run the unit tests.
What is your goal with
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Data)
? As per https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/, there must be a member given.
Can you give an example how the JSON you want to generate should look like?
(see also https://github.com/nlohmann/json/discussions/3865#discussioncomment-4370686)
Do you need further assistance with this issue?