I am using Cereal C++ v1.1.1 and similar to the example given in the documentation I am trying the following:
#include <sstream>
#include <iostream>
#include <cereal/archives/json.hpp>
int main() {
std::ostringstream os;
cereal::JSONOutputArchive archive(os);
int x = 12;
archive(CEREAL_NVP(x));
std::cout << os.str(); // JUST FOR DEMONSTRATION!
}
I expect to have the following:
{
"x":12
}
but the closing curly brace is missing. Any idea what is missing in the code?
Update:
adding archive.finishNode()
seems to solve the problem. But I would say that it's not the solution. According to the operator()
documentation, calling the operator serializes the input parameters, why should I add the finishNode
extra?