getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
821 stars 65 forks source link

How to handle modifying a structs properties #75

Closed RudyB closed 3 months ago

RudyB commented 3 months ago

I'm very interested in using your tool. The main question I have is regarding deserialization of a structure with properties that have changed.

For example, imagine version 1.0 of my software serializes a Data struct with an int32_t and a std::string. Version 2.0 adds a double to a data struct. How would I handle deserializing the older data struct in newer software?

liuzicheng1987 commented 3 months ago

Two possible solutions:

  1. You can make the additional fields optional

https://github.com/getml/reflect-cpp/blob/main/docs/optional_fields.md

  1. You can use API versioning

https://github.com/getml/reflect-cpp/blob/main/docs/backwards_compatability.md