Skip to content
Discussion options

You must be logged in to vote

This should be default behaviour now on master,

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

enum class PacketCompression  {
    NONE = 199,
    TEXTURE,
    GENERAL,
    ALL
};

struct Foo
{
    PacketCompression value;
};

JSONCONS_ALL_MEMBER_TRAITS(Foo,value)

int main()
{
    try
    {
        auto j = jsoncons::json::parse(R"({"value":199})");

        auto foo = j.as<Foo>();

        std::cout << "(1) " << (int)foo.value << "\n";

        std::string buffer;
        jsoncons::encode_json(foo, buffer);
        std::cout << "(2) " << buffer << "\n";
    }
    catch (const std::exception& e)
    {
        std::cout << e.what() << "\n";
    }
}

Output:

(1) 199
(2) {"value":199}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sarahlydia9868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants