USCiLab / cereal

A C++11 library for serialization
BSD 3-Clause "New" or "Revised" License
4.25k stars 767 forks source link

Issue when opening old version class with variant #843

Open AdiFogel opened 2 weeks ago

AdiFogel commented 2 weeks ago

I have a type that is defined as: using PropertiesVariant = sdbusplus::utility::dedup_variant_t< bool, std::string>; using BootOptionDataType = std::map<std::string, BootOptionDbus::PropertiesVariant>; using BootOptionsType = std::map<std::string, BootOptionDataType>;

The BootOption maps the property name to its value. The value can be a string of an unknown size and a boolean. The class has been changed and an additional boolean value has been added. The type actually did not change, because it still a variant of string and boolean. With the use of versioning, I'm trying to open the binary file, that has the basic class with a code that supports the extended type. deserialize: std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); cereal::BinaryInputArchive iarchive(is); iarchive(entry);

Load: Manager::BootOptionsType bootOptionsValues; archive(bootOptionsValues);

But I'm getting this error: "Failed cereal to serialize: Invalid 'index' selector when deserializing std::variant"

What is the correct type definition for handling this serialization? Is there a way that I will be able to deserialize the old file?

Any guidance or insights would be greatly appreciated!