json
json copied to clipboard
Allow ordered_json in NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE macro
Allow for ordered_json type to be used with the define macros provided in macro_scope.hpp.
Usage:
#include <cstdio>
#include <nlohmann/json.hpp>
struct mystruct
{
int x = 1;
double y = 2.0;
std::string z = "three";
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
(
mystruct,
z,
y,
x
);
int main()
{
mystruct ms;
const auto msjson = nlohmann::to_string(nlohmann::ordered_json{{ "mystruct", ms }});
const std::string expected = R"({"mystruct":{"z":"three","y":2.0,"x":1}})";
printf("%s\n",msjson .c_str());
printf("%s\n",expected.c_str());
return 0;
}
🔴 Amalgamation check failed! 🔴
The source code has not been amalgamated. @ArashPartow Please read and follow the Contribution Guidelines.
coverage: 99.649%. remained the same when pulling 4ac8d89d00d67808c58022131cb6ec001aeea153 on ArashPartow:arashpartow/ordered_json_NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE into a006a7a48bb30a247f0344b788c62c2806edd90b on nlohmann:develop.
This version in enum handling is what they should really be:
template<typename BasicJsonType> \
inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
See also #2843 and #2532
@nlohmann Happy for you to close this PR, as https://github.com/nlohmann/json/pull/4517 might be the more appropriate PR to make the necessary changes.
This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!
Closed in favor of #4597.