You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support serialisation of unique_ptr<> and shared_ptr<> #975
It will fail with a template error (get_json() isn't defined for unique_ptr). I can't see a good reason why that shouldn't work by default. I would expect null for null pointers and the actual value otherwise.
Yep, sorry for the delay - that looks excellent. Given that it is that easy to do without changing the library I wouldn't change it either. Though maybe add it to the Readme?
Activity
gregmarr commentedon Feb 16, 2018
I'm just a user, but I don't think having this library supporting automatic pointer dereference is a good idea.
Timmmm commentedon Feb 16, 2018
Because...
nlohmann commentedon Feb 17, 2018
I am also not sure whether such an implicit dereference under the hood is adding simplicity or rather surprise.
In any case, the described behavior can be achieved without changing the library:
(prints
[1,null])nlohmann commentedon Feb 19, 2018
Can I close this issue?
Timmmm commentedon Feb 28, 2018
Yep, sorry for the delay - that looks excellent. Given that it is that easy to do without changing the library I wouldn't change it either. Though maybe add it to the Readme?
theodelrieu commentedon Feb 28, 2018
There is already an example for
boost::optionalin the Readme, so I don't think adding one forunique_ptr/shared_ptris very useful.lattice0 commentedon Aug 29, 2020
Shouldn't at least
std::optionalbe supported?nlohmann commentedon Aug 29, 2020
For
std::optional, see #2229.RAnders00 commentedon Jan 9, 2024
Because it's not been posted by anyone, here is a complete implementation that also includes
from_json:(The same approach works for
std::shared_ptrwithstd::make_sharedas well)