Open merisanualex opened 1 month ago
@merisanualex , for cases such as this, you could use rfl::Literal
:
https://github.com/getml/reflect-cpp/blob/main/docs/literals.md
But if you want to use enums, I would have to think about what a good solution might look like. std::map won't do the trick, we need something that works at compile time.
I'm not sure if this works but perhaps a template specialization for each enum value and the specialization would contain the desired value?
template<>
struct rfl::EnumMapper<SomeName::FIRSTVALUE>
{
constexpr auto label = "some value";
};
template<>
struct rfl::EnumMapper<SomeName::SECONDVALUE>
{
constexpr auto label = "some other value";
};
@liuzicheng1987 is that possible to add?
@merisanualex , yes, I think something along these lines is possible.
@merisanualex , if you need a quick fix, you could try overloading rfl::parsing::Parser
for your enum.
I'm trying to make some types that match a json schema generated from python which look something like:
which in c++ would be:
obviously I'm losing the string values of the enums from python. I could instead use the value from python as the key for the c++ enum like so:
but reflect will (de)serialize the underscore as well. Is there any way to make reflect use spaces in this case? or perhaps a way to use std::map somewhere to convert the values?