Skip to content

Is it possible to skip write null for json_type_trails ? #594

Closed Answered by danielaparker
sarahlydia9868 asked this question in Q&A
Discussion options

You must be logged in to vote

@hiepsahplydia, I made two changes to your code, replacing OptionalV with std::optional, and

JSONCONS_ALL_MEMBER_TRAITS(OptionalExample, text, optional, optional_skip);

with

JSONCONS_N_MEMBER_TRAITS(OptionalExample, 1, text, optional, optional_skip);

(1 is the number of mandatory parameters). Then your example becomes:

#include <jsoncons/json.hpp>
#include <iostream>

using namespace jsoncons;

struct OptionalExample {

    std::string text;
    std::optional<std::string> optional;
    std::optional<std::string> optional_skip;

    explicit OptionalExample() = default;
    ~OptionalExample() = default;
};

namespace jsoncons
{
template <typename Json>
struct json_type_traits<Json, std::…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@sarahlydia9868
Comment options

Answer selected by sarahlydia9868
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