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

Add minimal annotation support #4082

Closed
wants to merge 13 commits into from
Closed

Add minimal annotation support #4082

wants to merge 13 commits into from

Conversation

marekpiotrowski
Copy link

Hey @nlohmann !

Hope you're having a great day!

After reading the guidelines and your discussion around comments in JSON, I got a feeling that this PR has no chance at all :D So, I was about to start writing documentation and considering I'd like to avoid redundant work, I though it'd make sense to check with you first.

Long story short, it's about annotating custom classes (annotations known at compile time) and dumping those when serializing (please see the tests or the example):

class ExampleClass {
private:
    int property1{1};
    double property2{2.5};
    std::string property3{"test"};
    std::map<std::string, int> property4{{"x", 1}, {"y", 2}};
    std::vector<double> property5{1.5, 5.4, 3.2};
public:
    ExampleClass() = default;

    NLOHMANN_DEFINE_TYPE_INTRUSIVE_ANNOTATED(ExampleClass, property1, "comment两两", 
                                                           property2, "multiline\ncomment2", 
                                                           property3, "comment3",
                                                           property4, "comment4",
                                                           property5, "comment5");
};

would produce:

{
    /* comment两两 */
    "property1": 1,
    /* multiline */
    /* comment2 */
    "property2": 2.5,
    /* comment3 */
    "property3": "test",
    /* comment4 */
    "property4": {
        "x": 1,
        "y": 2
    },
    /* comment5 */
    "property5": [
        1.5,
        5.4,
        3.2
    ]
}

If you'd ever consider merging this PR and allowing attachment of annotations known at compile time, I'll make sure that the documentation is consistent, code is amalgamated, will check the coverage, make sure redundant files are cleaned up etc. as per the guidelines. However, if you think it's a bad idea to introduce such functionality, I'm happy to keep this as a fork. I'll occasionally merge to your latest changes I guess.

The reason is that we've got plenty of JSON configuration files which are supposed to be filled by non-technical people. We use your brilliant plugin cus it's very robust and allows for ignoring comments when parsing. We've been annotating the dumped JSONs with some hard-core text manipulations in "post-processing", but it's horrible. Maintaining such documentation outside of the code is pretty much impossible so we had no choice though.

But now I thought that I could slightly extend your serializer and convenient macros for annotating the properties of custom classes.

Please let me know if there's any chance we could merge such functionality. If that's not the case, I'll have to prepare the documentation differently ;)

Cheers,
Marek

@github-actions
Copy link

github-actions bot commented Aug 4, 2023

🔴 Amalgamation check failed! 🔴

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

@coveralls
Copy link

Coverage Status

coverage: 98.848% (-1.2%) from 100.0% when pulling bff36b4 on marekpiotrowski:add-minimal-annotation-support into 5d27543 on nlohmann:develop.

@marekpiotrowski marekpiotrowski closed this by deleting the head repository Oct 15, 2023
@github-actions
Copy link

🔴 Amalgamation check failed! 🔴

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

@github-actions github-actions bot added the CI label Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants