Is it possible to convert raw string value of enum to enum? #1611
-
Whilst i was able to find a way to serialize enum to string, I now need to deserialize a string to enum from lets say a database. from example to serialize we do
That works great, but as soon as i tried to deserialize I couldn't find a way. So far i tried
none seem to work, is there such functionality?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Using |
Beta Was this translation helpful? Give feedback.
-
Are you using enum class Color { Red, Green, Blue };
template <>
struct glz::meta<Color> {
using enum Color;
static constexpr auto value = enumerate(Red,
Green,
Blue
);
}; |
Beta Was this translation helpful? Give feedback.
-
I think you might be confused thinking this is a quoted string: |
Beta Was this translation helpful? Give feedback.
So, you're getting your enum from your database as a non-quoted string and want to get it into an enum value again. You could add quotes to make it a valid JSON string and then
glz::read
will work. Or, you could use a library like simple_enum, which also has support for working with Glaze.