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

how to serialize std::map and std::set ? #27

Closed
yanzixiang opened this issue Jun 27, 2022 · 2 comments
Closed

how to serialize std::map and std::set ? #27

yanzixiang opened this issue Jun 27, 2022 · 2 comments

Comments

@yanzixiang
Copy link

can I use this to serialize std::map and std::set ?
for example i define a set A,
I use JS::serializeStruct(A) give me a error.
expect the output is ["1" , "2", "3" ]...

@jorgen
Copy link
Owner

jorgen commented Jun 27, 2022

Hi,
I have been putting off making these TypeHandlers since then we have to include <map>, <set>, <unordered_set> in json_struct.h and suddenly everyone has has these includes just by including json_struct. I regret most of the includes in there already, but changing this can break user code, (I still have some members with spelling mistakes because chaning it will break code).

I have come up with this scheme where the TypeHandlers are guarded by their own include guards. So if you want the std::map TypeHandler then you will have to define JS_STL_MAP before including json_struct.h. The unit test should give you the idea: https://github.com/jorgen/json_struct/blob/master/tests/json-unordered-map.cpp#L4.

This is available in 3ddf92e.

@yanzixiang
Copy link
Author

you just add JS_STL_MAP to support map ,
what about set ?
without this,
how to serialize a list without knowing how many items in it ?

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

No branches or pull requests

2 participants