Having problem with Class that has a variable that is itself a Class #4464
Unanswered
earlthesquirrel
asked this question in
Q&A
Replies: 1 comment 1 reply
-
The library doesn't currently support |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm trying to use code that "seems" to match up to the examples and for some reason I'm getting a compiler error that I can't quite figure out how to resolve
I have a file that I define all of my NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE macros in, for each of the classes that I want to be able to serialize. (it's called Messages)
I have a line like this :
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CustomData, vendorId, additionalProperties)
which has no issues. (CustomData only has public variables)
CustomData's public variable are: std::string vendorId; and std::map<std::string, nlohmann::json> additionalProperties;
I have another line:
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(EVSE, customData, id, connectorId)
EVSE's public variables are : std::optional customData; and int id and std::optional connectorId;
EVSE only has public variables.
The second line generates this error:
Messages.cpp: error: no match for ‘operator=’ (operand types are ‘nlohmann::json_abi_v3_11_3::basic_json<>::value_type’ {aka ‘nlohmann::json_abi_v3_11_3::basic_json<>’} and ‘const std::optional<Ocpp2_0_1_Messages::CustomData>’)
26 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE (EVSE, customData, id, connectorId)
I've RTFM and dug around, but cannot find any reference as to why this wouldn't work. I can't find an exact matching case in the examples, but it doesn't seem that odd what I'm trying.
It also fails for any class that has a simple "CustomData customData" variable. (or any other class variable)
I'm obviously missing something basic... can anyone point me towards an example or documentation that would explain to me how to resolve this?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions