Skip to content
New issue

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

warning on at(nlohmann::json_pointer) #4103

Open
1 of 2 tasks
manifolds opened this issue Aug 9, 2023 · 0 comments
Open
1 of 2 tasks

warning on at(nlohmann::json_pointer) #4103

manifolds opened this issue Aug 9, 2023 · 0 comments

Comments

@manifolds
Copy link

manifolds commented Aug 9, 2023

Description

warning on at(nlohmann::json_pointer)

warning: ‘nlohmann::json_abi_v3_11_2::json_pointer::operator nlohmann::json_abi_v3_11_2::json_pointer::string_t() const [with RefStringType = std::basic_string; nlohmann::json_abi_v3_11_2::json_pointer::string_t = std::basic_string]’ is deprecated (declared at /home/tty2099/Workspace/AutoTradingSystem/third_party/nlohmann_json/include/nlohmann/detail/json_pointer.hpp:81): Since 3.11.0; use to_string() [-Wdeprecated-declarations]

It's warning when compiling the code, but It can find the node correctly. When I call with at(nlohmann::json_pointer::to_string()), it cannot find the json node.

I cannot understand the purpose of the find function with json_pointer parameter, it will not find the node when I call it with the json_pointer paramter or with the json_pointer::to_string() paramter.

Reproduction steps

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

int main(int argc, char** argv)
{
    nlohmann::json j2 = {
      {"pi", 3.141},
      {"happy", true},
      {"name", "Niels"},
      {"nothing", nullptr},
      {"answer", {
        {"everything", 42}
      }},
      {"list", {1, 0, 2}},
      {"object", {
        {"currency", "USD"},
        {"value", 42.99}
      }}
    };

    nlohmann::json_pointer<std::string> ptr;
    ptr.push_back("object");
    ptr.push_back("value");
    std::cout<<"pointer value: "<< j2.at(ptr).get<double>()<<std::endl;
    std::cout<<"pointer value: "<< j2.at(ptr.to_string()).get<double>()<<std::endl;
    auto itr = j2.find(ptr);
    if(itr!=j2.cend()) std::cout<<"find --- 0"<<std::endl;
    itr = j2.find(ptr.to_string());
    if(itr!=j2.cend()) std::cout<<"find --- 1"<<std::endl;
    return EXIT_SUCCESS;
}

Expected vs. actual results

I think at(nlohmann::json_pointerstd::string) and at(nlohmann::json_pointerstd::string::to_string()) calls return the same result, nlohmann::json should find the node according the path that nlohmann::json_pointerstd::string supplied.

I think the find function should also be work in this way.

Minimal code example

No response

Error messages

No response

Compiler and operating system

CentOS7

Library version

3.11.0

Validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant