Skip to content

Enum default serialization #1951

@razaqq

Description

@razaqq

Lets say i have the following

enum class enum_t
{
    foo = 0,
    bar = 1,
};

template<>
struct glz::meta<enum_t>
{
    using enum enum_t;
    static constexpr auto value = enumerate(
        "foo", foo,
        "bar", bar
    );
};

enum_t value = static_cast<enum_t>(100);
std::string buffer{};
glz::write_json(value , buffer);
expect(buffer == "100");

By default serialization falls back to int for enums, this can cause a lot of issues with parsers expecing strings.
My question is how can i serialize unknown enum values as for example "unknown"?

Similarly what happens if there is such an inconsistency in a json object, is there a way to skip that value?

Originally posted by @razaqq in #1923

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions