Open rotolof opened 1 year ago
Any updates about this PR?
I just solved the conflict that had arisen in the meantime.
I am currently finishing #2998 to finally have a stable CI. Once this is merged, please update your branch.
(Also, please update from the develop branch and fix the conflicts.)
since this code now actually modifies the json object from base - what do you guys think about using merge_patch
or +=
instead of =
for each member?
for example:
#define NLOHMANN_JSON_PAIR(member) {#member, nlohmann_json_t.member},
#define NLOHMANN_INIT_PAIRS(...) \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_PAIR, __VA_ARGS__))
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_INHERITANCE(derived, base, ...) \
void to_json(nlohmann::json &nlohmann_json_j, \
derived const &nlohmann_json_t) { \
to_json(nlohmann_json_j, static_cast<base const &>(nlohmann_json_t)); \
nlohmann_json_j.merge_patch(nlohmann::json{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_INIT_PAIRS(__VA_ARGS__))}); \
} \
void from_json(nlohmann::json const &nlohmann_json_j, \
derived &nlohmann_json_t) { \
from_json(nlohmann_json_j, static_cast<base &>(nlohmann_json_t)); \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
}
I updated to the latest develop and added documentation, let me know it is ok now
The source code has not been amalgamated. @rotolof Please read and follow the Contribution Guidelines.
The source code has not been amalgamated. @rotolof Please read and follow the Contribution Guidelines.
@rotolof Looks like you might be using a different version of astyle (perhaps even a newer one) which has different behavior than the current version being used. https://github.com/nlohmann/json/pull/4180#issuecomment-1758627278
@gregmarr Thanks, I was using macOS brew's astyle that is 3.4.9. I tried with the suggested 3.1 but it does not support squeeze-lines
, wtf?
Comment that line from the config and try again. Sorry for the inconvenience - I did not find the time to fix this yet.
Are there any chances to release that soon? Seems like the most of work has been done and it just hanging almost a year now.
Are there any chances to release that soon? Seems like the most of work has been done and it just hanging almost a year now.
Sorry, I completely forgot about this until now! Let me check it again.
Is this change ok now? Can it possibly be integrated soon?
Is this change ok now? Can it possibly be integrated soon?
I think that everything is fine, I had updated with the latest develop and all checks had passed, is anything missing @nlohmann?
I created the new macros:
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT
to recreate the proposed fix to #2199. The macros accept as second parameter the base class.
Usage example:
What they do is basically calling the
to_json
/from_json
functions of the base class before serialising/deserialising the class members: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.