danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
715 stars 163 forks source link

Enum-keyed maps bad serialization #426

Closed aperry5544 closed 1 year ago

aperry5544 commented 1 year ago

When serializing out a map that uses an enum as the key, the resulting map adds extra escaped quotes around the key name.

Example...

enum class MyEnum
{
    Value0,
    Value1
};

JSONCONS_ENUM_TRAITS(MyEnum, Value0, Value1)

std::map<MyEnum, int> my_map;
my_map[MyEnum::Value0] = 5;
my_map[MyEnum::Value1] = 10;

When serializing my_map it results in the following...

...
"my_map": {
    "\"Value0\"": 5,
    "\"Value1\"": 10
}
...

I would instead expect the output to be

...
"my_map": {
    "Value0": 5,
    "Value1": 10
}
...
danielaparker commented 1 year ago

Thanks for reporting this, fixed on master.