Skip to content

How to simplify the task of write to_json function for derived class ? #2223

Answered by nlohmann
gzliudan asked this question in Q&A
Discussion options

You must be logged in to vote

If some of the classes share code, you can call to_json of the base class explicitly, e.g. by

nlohmann::to_json(j, static_cast<Base&>(obj));

Further note there is an update function to merge/update objects.

A related issue: #2199

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gzliudan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2223 on June 27, 2020 10:28.