-
-
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
Add serialization-only user defined type macros #3816
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation. See https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/api/macros/index.md for a starting point.
(Also, please update from the develop branch as it has a working CI now.) |
I also noticed that the source code highlighting is a bit off in these pages, see #4169. |
f0843f4
to
a2d5270
Compare
1b0390c
to
ba7f94d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
This pull requests adds
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE
andNLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE
macros.Suppose we have a non-default-constructible type
person
and another type that contains a field of typeperson
. For example:An attempt to use the
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
macro to generate serialization/deserialization code will lead to a compilation error:README.md
provides an example how to fix this by providing a specialization ofadl_serializer
. However, this requires writing quite a bit of code and might even be unnecessary in cases when we only need serialization without deserialization.In this situations, we can use added macros to generate only
to_json
functions.Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filessingle_include/nlohmann/json.hpp
andsingle_include/nlohmann/json_fwd.hpp
. The whole process is described here.Please don't
#ifdef
s or other means.