We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For number "9223372036854775808" (int64_t::max() + 1) I expects that json.get<nlohmann::json::number_integer_t>() throws exception.
int64_t::max()
json.get<nlohmann::json::number_integer_t>()
https://godbolt.org/z/v4ejoPszf
#include "nlohmann/json.hpp" #include <iostream> int main(int, char **) { auto json = nlohmann::json::parse(R"({ "package size": 9223372036854775808 })"); auto [key, number] = *json.items().begin(); std::cout << number.get<nlohmann::json::number_integer_t>() << std::endl; return 0; }
I expects to get exception.
Program stdout -9223372036854775808
develop
The text was updated successfully, but these errors were encountered:
Also it's relevant for is_number_integer check:
is_number_integer
#include "nlohmann/json.hpp" #include <iostream> int main(int, char **) { auto json = nlohmann::json::parse(R"({ "package size": 9223372036854775808 })"); auto [key, number] = *json.items().begin(); if (number.is_number_integer()) { std::cout << number.get<nlohmann::json::number_integer_t>() << std::endl; } return 0; }
bash :> ./build/default/main -9223372036854775808
Sorry, something went wrong.
The library differentiates between signed and unsigned integers (see https://json.nlohmann.me/features/types/number_handling/). is_number_integer() returns true for either integer type (see https://json.nlohmann.me/api/basic_json/is_number_integer/).
is_number_integer()
So with get<nlohmann::json::number_integer_t>() you actually cast an std::uint64_t to a std::int64_t.
get<nlohmann::json::number_integer_t>()
std::uint64_t
std::int64_t
#include <nlohmann/json.hpp> int main() { const auto j = nlohmann::json::parse("9223372036854775808"); assert(j.is_number_unsigned()); std::uint64_t n = j; assert(n == 9223372036854775808U); }
No branches or pull requests
What is the issue you have?
For number "9223372036854775808" (
int64_t::max()
+ 1) I expects thatjson.get<nlohmann::json::number_integer_t>()
throws exception.Can you provide a small but working code example?
https://godbolt.org/z/v4ejoPszf
What is the expected behavior?
I expects to get exception.
And what is the actual behavior instead?
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: