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

Is here any elegant way to combine serialization and deserialization code? #2028

Closed
NukeBird opened this issue Apr 5, 2020 · 4 comments
Closed
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@NukeBird
Copy link

NukeBird commented Apr 5, 2020

I know everything can be much easier with reflection, but sadly C++ doesn't have it

When I'm writing code I noticed I'm repeating myself, serialization and deserialization looks very similar

How can I serealize and deserialize things in elegant way? For example lets say we want to serialize this:

struct Human
{
std::string name;
int age;
};

and then deserialize it back. As I said earlier, if it's possible I wanna combine serialization and deserialization code

thanks for your help in advance!

@NukeBird NukeBird changed the title is here any elegant way to combine serialization and deserialization code? Is here any elegant way to combine serialization and deserialization code? Apr 5, 2020
@NukeBird
Copy link
Author

NukeBird commented Apr 5, 2020

black macro magic?

@nlohmann
Copy link
Owner

nlohmann commented Apr 5, 2020

Yes. We have a macro for simplifying the enum conversion, see https://github.com/nlohmann/json#specializing-enum-conversion. If you have an idea to achieve something similar, please let me know!

@stale
Copy link

stale bot commented May 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale 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 May 6, 2020
@stale stale bot closed this as completed May 13, 2020
@nlohmann
Copy link
Owner

This issue is fixed in #2175.

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated labels Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants