cereal icon indicating copy to clipboard operation
cereal copied to clipboard

I need a way to skip prologue and epilogue in JSON sometimes.

Open Rational-pi opened this issue 1 year ago • 1 comments

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);
}
}

Rational-pi avatar Oct 12 '24 10:10 Rational-pi

save_minimal should do what you want I believe.

Devacor avatar May 19 '25 05:05 Devacor