cereal
cereal copied to clipboard
I need a way to skip prologue and epilogue in JSON sometimes.
I recurrently need to write some C++ objects not as objects in JSON. For example, QString. If I implement the standard serialization, I end up with:
"QStingVariableName"{ "Value0":"whatever"}
but I need it to be:
"QStingVariableName":"whatever"
I hacked a bit the json archive to do so but It would be great to have a way to do so canonicaly
there is my hack: diff.txt
I use it like that for exemple for QString:
namespace cereal /*QString*/{
template <> struct SkipPrologFlag<QString>{};
template <class Ar>
inline void save(Ar& ar, const QString& str){
ar.saveValue(str.toStdString());
}
template <class Ar>
inline void load(Ar& ar, QString& str){
std::string tmp;
ar.loadValue(tmp);
str=QString::fromStdString(tmp);
}
}
save_minimal should do what you want I believe.