netheril96 / StaticJSON

Fast, direct and static typed parsing of JSON with C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support for enumset

xphoenix opened this issue · comments

Thanks for the lib, saved me a lot of time.

As usual I did 80% of work very fast and them stack a bit with enum sets. I have a few, looks like so:

enum class MySet : uint8_t { F1 = 1, F2 = 2, F4=4 };
inline MySet operator|(MySet lhs, MySet rhs) { return MySet(uint8_t(lhs) | uint8_t(rhs)); }
....

It would be nice to serialize it as an array of set bit names:

["F1", "F4"]

So I was looking in EnumHandler and ArrayHandler to figure out how to merge them in order to archive that kind of serialization, but I've failed at the end - templates are not at my fingertips.

Do you have any kind of documentation about serializer internals? Or an advice on how that kind of trick could be done :)

It is a bit complicated to write a custom handler for arrays. A hook to allow conversion may be better for your use case. I need to think about how to design the API.

I just added a new functionality: custom conversion. You can declare vector<string as the shadow type, and write the to and from functions yourself. If you have any more questions, feel free to reopen the issue.