Merge pull request #6425 from yorickvP/fix-6424
Add custom to_json and from_json functions for ExperimentalFeature
This commit is contained in:
commit
2ffc5a4542
|
@ -58,4 +58,18 @@ std::ostream & operator <<(std::ostream & str, const ExperimentalFeature & featu
|
||||||
return str << showExperimentalFeature(feature);
|
return str << showExperimentalFeature(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json& j, const ExperimentalFeature& feature) {
|
||||||
|
j = showExperimentalFeature(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json& j, ExperimentalFeature& feature) {
|
||||||
|
const std::string input = j;
|
||||||
|
const auto parsed = parseExperimentalFeature(input);
|
||||||
|
|
||||||
|
if (parsed.has_value())
|
||||||
|
feature = *parsed;
|
||||||
|
else
|
||||||
|
throw Error("Unknown experimental feature '%s' in JSON input", input);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,4 +51,11 @@ public:
|
||||||
MissingExperimentalFeature(ExperimentalFeature);
|
MissingExperimentalFeature(ExperimentalFeature);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semi-magic conversion to and from json.
|
||||||
|
* See the nlohmann/json readme for more details.
|
||||||
|
*/
|
||||||
|
void to_json(nlohmann::json&, const ExperimentalFeature&);
|
||||||
|
void from_json(const nlohmann::json&, ExperimentalFeature&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue