Skip to content
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

Fix text in C++ default statement #2623

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Crayon2000
Copy link
Contributor

@Crayon2000 Crayon2000 commented Jun 29, 2024

Description

  • Fix text in C++ default statement
  • Fix some typos in comments

Related Issue

None that I know of.

Motivation and Context

It fixes an error in the C++ output code. Problem was introduced in PR #2431.

How Has This Been Tested?

Tested with this command: quicktype --lang cpp --src-lang json ./test/inputs/json/samples/us-senators.json

Previous Behaviour / Output

Before the changes we can see that we are getting a [object Object] for all enumeration names:

    inline void to_json(json & j, const SenatorRankLabel & x) {
        switch (x) {
            case SenatorRankLabel::JUNIOR: j = "Junior"; break;
            case SenatorRankLabel::SENIOR: j = "Senior"; break;
            default: throw std::runtime_error("Unexpected value in enumeration \"[object Object]\": " + std::to_string(static_cast<int>(x)));
        }
    }

    inline void from_json(const json & j, Title & x) {
        if (j == "Sen.") x = Title::SEN;
        else { throw std::runtime_error("Input JSON does not conform to schema!"); }
    }

    inline void to_json(json & j, const Title & x) {
        switch (x) {
            case Title::SEN: j = "Sen."; break;
            default: throw std::runtime_error("Unexpected value in enumeration \"[object Object]\": " + std::to_string(static_cast<int>(x)));
        }
    }

New Behaviour / Output

After the changes, we get the proper enumeration names:

    inline void to_json(json & j, const SenatorRankLabel & x) {
        switch (x) {
            case SenatorRankLabel::JUNIOR: j = "Junior"; break;
            case SenatorRankLabel::SENIOR: j = "Senior"; break;
            default: throw std::runtime_error("Unexpected value in enumeration \"SenatorRankLabel\": " + std::to_string(static_cast<int>(x)));
        }
    }

    inline void from_json(const json & j, Title & x) {
        if (j == "Sen.") x = Title::SEN;
        else { throw std::runtime_error("Input JSON does not conform to schema!"); }
    }

    inline void to_json(json & j, const Title & x) {
        switch (x) {
            case Title::SEN: j = "Sen."; break;
            default: throw std::runtime_error("Unexpected value in enumeration \"Title\": " + std::to_string(static_cast<int>(x)));
        }
    }

@Crayon2000
Copy link
Contributor Author

For some reason the 'objective-c' test never run. Should I do something about this so my PR can be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant