netheril96 / StaticJSON

Fast, direct and static typed parsing of JSON with C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autojsoncxx does not handle duplicate fields

Bienne opened this issue · comments

Autojsoncxx does not handle duplicate fields. Autojsoncxx only keeps the last occurence.
Can you throw an error when processing duplicate fields?
Thank you.

Here is a sample:


spec file:
[
{
"name": "TestInfo",
"namespace": "Test",
"members": [
["std::string", "param_1", {"required": true}],
["autojsoncxx::utility::int64_t", "param_2", {"default": 0}]
]
}
]


main.cpp:

include "test.hpp"

include "autojsoncxx/autojsoncxx.hpp"

include

int main(int /argc/, char _/_argv*/[])
{
const std::string rawRequest = "{"param_1": "value_1", "param_1": "value_2", "param_2": 123}";

autojsoncxx::ParsingResult parsingResult;

Test::TestInfo info;
autojsoncxx::from_json_string(rawRequest, info, parsingResult);

if(parsingResult.has_error())
{
    std::cout << "error" << std::endl;
    return -1;
}

std::cout << info.param_1 << std::endl; // error: param_1 field occurs twice ( "value_1" and "value_2")
return 0;

}

Implemented in d0bcfc2.