You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice that for all types, if they're optional, they're std::shared_ptr<>. Then in the to_json() methods, there's an (if x.pointer()) ... method, to check for null before adding to the json object. The "any" type is a nlohmann::json object, and keeping with the same paradigm, an optional "any" type should be a std::shared_ptr<nlohmann::json>, but is generated as a nlohmann::json object instead. This almost works since an empty json object does have the concept of "null". Unfortunately, nlohmann/json does not have a bool operator (nlohmann/json#951), so the if (x.get_alpha()) line above is invalid.
Given the following JSON schema:
The following C++ is generated (with the --hide-null-optional and --no-boost options):
Notice that for all types, if they're optional, they're std::shared_ptr<>. Then in the to_json() methods, there's an (if x.pointer()) ... method, to check for null before adding to the json object. The "any" type is a nlohmann::json object, and keeping with the same paradigm, an optional "any" type should be a
std::shared_ptr<nlohmann::json>
, but is generated as anlohmann::json
object instead. This almost works since an empty json object does have the concept of "null". Unfortunately, nlohmann/json does not have a bool operator (nlohmann/json#951), so theif (x.get_alpha())
line above is invalid.I think this all boils down to one bad line: https://github.com/quicktype/quicktype/blob/master/src/quicktype-core/language/CPlusPlus.ts#L851
Simply removing that line seems to fix the problem.
The text was updated successfully, but these errors were encountered: