I am interested to use JSON for storing the initial parameters for an application written in C++. Currently I am testing the nlohmann/json library for read/write data from/to JSON files.
I have the following class structure:
class Layer {
public:
std::string name;
LayerType type;
...
};
class Network {
public:
std::string name;
std::vector<Layer> layers;
...
};
and the serialize/deserialize methods are here:
void to_json(json& j, const Layer& layer) {
j = json{
{"name", layer.name},
{"type", layer.type}
};
}
void from_json(const json& j, Layer& layer) {
j.at("name").get_to(layer.name);
j.at("type").get_to(layer.type);
}
void to_json(json& j, const Network& network) {
j = json{
{"name", network.name},
{"layers", network.layers}
};
}
void from_json(const json& j, Network& network) {
j.at("name").get_to(network.name);
j.at("layers").get_to(network.layers);
}
So, up to here, these classes are fine and can be used to read and write from and to JSON.
And now comes the question. What if I decide to use addresses of layers in the Network class?
class Network {
public:
std::vector<Layer*> layers;
...
};
How should I rewrite the serialize/deserialize methods? Where can I find a similar example?
SK