cereal icon indicating copy to clipboard operation
cereal copied to clipboard

feature: named variants in json serialization

Open amiartus opened this issue 4 years ago • 2 comments

Hello,

I made some changes to how variants are represented in json for my use case and putting it here in case you would also find it useful.

example output:

  1. g++ --std=c++17 m.cpp
{
    "value0": {
        "variant": {
            "index": 0,
            "data": {
                "id": 5
            }
        }
    }
}
  1. g++ -DCEREAL_NAMED_VARIANT --std=c++17 m.cpp
{
    "value0": {
        "variant": {
            "type": "LoadInstrument",
            "LoadInstrument": {
                "id": 5
            }
        }
    }
}

code example: https://gist.github.com/miartad/3b290142284a4bed0a8c1736d9cc62ed

amiartus avatar Jan 31 '21 13:01 amiartus

As discussed in another pull request, this is problematic since std::variant allows for the same type to exist multiple times. So this makes no sense in general.

WSoptics avatar Feb 15 '21 14:02 WSoptics

are variants with multiples of same types supported by cereal? in my test these types of variants do not compile with cereal.

amiartus avatar Feb 15 '21 23:02 amiartus