iguana icon indicating copy to clipboard operation
iguana copied to clipboard

Could not represent null fields...

Open BOT-Man-JL opened this issue 7 years ago • 0 comments

#include <iostream>
#include "iguana/json.hpp"

struct Model {
    std::string str;
    int num;
};
REFLECTION (Model, str, num);

void parseJson (const char *json)
{
    Model model;
    model.str = "";
    model.num = 0;
    iguana::json::from_json (model, json);
    std::cout << "str: '" << model.str << "', "
        << "num: " << model.num << std::endl;
}

//$ clang++ json_test.cpp -std=c++14 -o json_test && ./json_test
int main (int argc, char *argv[])
{
    parseJson (R"({ "str": "string", "num": 6, "dummy": 0 })");  // str: 'string', num: 6
    parseJson (R"({ "str": "string", "num": 6 })");              // str: 'string', num: 6
    parseJson (R"({ "str": "string" })");                        // str: 'string', num: 0
    parseJson (R"({ "dummy": 0 })");                             // str: '', num: 0
    parseJson (R"({ "dummy": 0, "num": 6 })");                   // str: '', num: 0
    parseJson (R"({ "dummy": 0, "num": 6, "str": "string" })");  // str: '', num: 0
    return 0;
}
  • Unable to tell if a field presents or not..
  • Failed to parse json with some dummy field...

BOT-Man-JL avatar Sep 25 '17 02:09 BOT-Man-JL