-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
How to override default string serialization? #2079
Labels
Comments
No, this is currently not possible without changing the code of the original serializer, see |
Alright, thank you. I was able to make this change in the following to switch (val.m_type) {
// ...
case value_t::string: {
if ((*val.m_value.string).empty()) {
o->write_characters("null", 4);
} else {
o->write_character('\"');
dump_escaped(*val.m_value.string, ensure_ascii);
o->write_character('\"');
}
return;
}
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe what you want to achieve
I would like to be able to override the default string serialization to return a
null
value for empty strings. For instance,source
output
Describe what you tried
void to_json(nlohmann::json &j, const std::string &s)
. Redefinition error while linking.to_json
, for example,source
output
I'm working on my first CPP project and admittedly inexperienced templating or concepts like SFINAE. If anyone has a possible solution or point out where I'm going wrong it would appreciated. Thank you!
Describe which system (OS, compiler) you are using
Linux 5.6.6 x86-64, clang 10.0.0
Describe which version of the library you are using (release version, develop branch)
develop
branchThe text was updated successfully, but these errors were encountered: