Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Rational-pi opened this issue Oct 12, 2024 · 0 comments
Open

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

Rational-pi opened this issue Oct 12, 2024 · 0 comments

Comments

@Rational-pi
Copy link

Rational-pi commented Oct 12, 2024

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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant