README: adjust boost::optional example
The "from_json" example for boost::optional is not complete and should also handle the 'none' case.
This commit is contained in:
parent
f642934b18
commit
f2873e6d3a
1 changed files with 3 additions and 1 deletions
|
@ -563,7 +563,9 @@ namespace nlohmann {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void from_json(const json& j, boost::optional<T>& opt) {
|
static void from_json(const json& j, boost::optional<T>& opt) {
|
||||||
if (!j.is_null()) {
|
if (j.is_null()) {
|
||||||
|
opt = boost::none;
|
||||||
|
} else {
|
||||||
opt = j.get<T>(); // same as above, but with
|
opt = j.get<T>(); // same as above, but with
|
||||||
// adl_serializer<T>::from_json
|
// adl_serializer<T>::from_json
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue