Replies: 3 comments
-
I didn't know NLOHMANN_JSON_SERIALIZE_ENUM, I will have a look at it. In the meantime here is how we serialize any enums using magic_enum:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Ok, in your example I am not sure why the Enum class exists. You can just declare that enum globally and then it would work. if you want the class you will have to define serialization for it as well as the macro only does this for the actual enum. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Do you need further assistance with this issue? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm sorry to ask this but I just can't seem to figure out how to de-serialize an enum that is part of a class/struct. Here is an example of what I'm trying to do:
The above compiles with g++-9 on ubuntu 18.04 using: g++ -o enumTest -std=c++2a enumTest.cpp
The result is an exception:
terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.302] type must be number, but is string
Aborted (core dumped)
I understand this has something to do with the namespaces and falls under this statement in the documentation:
but I just don't know how to fix it.
I'd appreciate it if someone more adept at C++ would take a look.
Beta Was this translation helpful? Give feedback.
All reactions