Skip to content

Allow ordered_json in NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE macro #4528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Allow ordered_json in NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE macro #4528

wants to merge 1 commit into from

Conversation

ArashPartow
Copy link

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;
}

@ArashPartow ArashPartow requested a review from nlohmann as a code owner December 6, 2024 06:46
@github-actions github-actions bot added the S label Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @ArashPartow
Please read and follow the Contribution Guidelines.

@coveralls
Copy link

coveralls commented Dec 6, 2024

Coverage Status

coverage: 99.649%. remained the same
when pulling 4ac8d89 on ArashPartow:arashpartow/ordered_json_NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
into a006a7a on nlohmann:develop.

@github-actions github-actions bot added M and removed S labels Dec 6, 2024
@gregmarr
Copy link
Contributor

gregmarr commented Dec 6, 2024

This version in enum handling is what they should really be:

    template<typename BasicJsonType>                                                            \
    inline void from_json(const BasicJsonType& j, ENUM_TYPE& e)                                 \

@gregmarr
Copy link
Contributor

gregmarr commented Dec 6, 2024

See also #2843 and #2532

Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with #4528 (comment) - a templated version would be a cleaner solution. Especially if more specializations are added such as #4517.

@ArashPartow
Copy link
Author

@nlohmann Happy for you to close this PR, as #4517 might be the more appropriate PR to make the necessary changes.

Copy link

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!

@github-actions github-actions bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 18, 2025
@nlohmann
Copy link
Owner

Closed in favor of #4597.

@nlohmann nlohmann closed this Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants