Skip to content

Enum-Flag Default Values #689

Description

@PapeCoding

Currently I try to use reflect-cpp to serialize a struct to json and back.

enum class PlatformFlag
{
	NONE = 0,
	LINUX = 1 << 0,
	WINDOWS = 1 << 1,
	MAC = 1 << 2,
	ALL = LINUX | WINDOWS | MAC
};
constexpr PlatformFlag operator&(PlatformFlag const a, PlatformFlag const b);
constexpr PlatformFlag operator|(PlatformFlag const a, PlatformFlag const b);
inline PlatformFlag& operator|=(PlatformFlag& a, PlatformFlag const b);

[...]

struct myStruct
{
	PlatformFlag supportedPlatforms = PlatformFlag::NONE;
};

Serializing to json without setting a value yields something like:

{
    "supportedPlatforms": ""
}

and reading it back then errors out with: Invalid enum value: ''. Must be one of [NONE, LINUX, WINDOWS, MAC]..

Am I missing something? Ideally it would either serialize to "NONE" or allow the empty string here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions