Skip to content

UInt64 is not convertible to uintValue? #802

Closed
@JalapenoGremlin

Description

@JalapenoGremlin

Perhaps I'm using the library incorrectly, but it seems to me that a UInt64 should return true when checking to see if it is convertible to a uintValue....

#include <json/json.h>

#include <cstdint>
#include <iostream>
#include <string>
#include <sstream>

int main(int argc, char *argv[])
{
    Json::Value a = Json::Value::UInt64(8589934592ULL);
    bool convertible_p = a.isConvertibleTo(Json::ValueType::uintValue);
    std::cout << a << " is convertible to uintValue: "
              << std::boolalpha << convertible_p << std::endl;

    Json::Value root;
    std::stringstream ss;
    ss << "{    \"a\": 8589934592 }";
    ss >> root;
    std::cout << root << std::endl;
    uint64_t b = root.get("a",0).asUInt64();
    std::cout << b << std::endl;
    convertible_p = root.get("a",0).isConvertibleTo(Json::ValueType::uintValue);
    std::cout << b << " is convertible to uintValue: "
              << std::boolalpha << convertible_p << std::endl;
    if (root.get("a",0).type() == Json::ValueType::uintValue) {
        std::cout << "     BUT the type is a Json:ValueType:uintValue" << std::endl;
    }

    return 0;
}

Returns:

8589934592 is convertible to uintValue: false
{
	"a" : 8589934592
}
8589934592
8589934592 is convertible to uintValue: false
     BUT the type is a Json:ValueType:uintValue

Compilation line was:
g++-4.9 -std=c++11 -I ~/src/jsoncpp/include/ test.cpp -L ~/build/src/lib_json -l jsoncpp

It looks like the underlying type of a UInt64 is a Json::ValueType::uintValue, but it's not convertible to such a type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions