Skip to content

Commit 99b0240

Browse files
committed
OptionalExample
1 parent d129a9e commit 99b0240

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

doc/ref/corelib/reflect/json_conv_traits.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ macros that make specializing `json_conv_traits` for your own types easier.
6161
```cpp
6262
#include <jsoncons/json.hpp>
6363
#include <string>
64+
#include <optional>
6465
#include <iostream>
6566
#include <cassert>
6667

@@ -145,10 +146,13 @@ struct json_conv_traits<Json, ns::OptionalExample>
145146
{
146147
Json j = jsoncons::make_obj_using_allocator<Json>(aset.get_allocator(), json_object_arg);
147148
j.try_emplace("text", val.text);
148-
j.try_emplace("optional", val.optional ? *val.optional : nullptr);
149+
if (val.optional)
150+
{
151+
j.try_emplace("optional", *val.optional);
152+
}
149153
if (val.optional_skip)
150154
{
151-
j.try_emplace("optional_skip", val.optional_skip);
155+
j.try_emplace("optional_skip", *val.optional_skip);
152156
}
153157
return j;
154158
}

0 commit comments

Comments
 (0)