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

Construction in a member initializer list using curly braces is set as 'array' #1742

Closed
kyeonghopark opened this issue Sep 9, 2019 · 4 comments

Comments

@kyeonghopark
Copy link

  • What is the issue you have?
    The type of json object is set as 'array' in a constructor of an inherited class.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

class child : public nlohmann::json {
 public:
  explicit child(const nlohmann::json &j) : nlohmann::json{j} {}
};

nlohmann::json j = nlohmann::json::parse("{\"a\":1}");
child c{j};

  • What is the expected behavior?
    The type of c should be 'object', not 'array'.

  • And what is the actual behavior instead?
    The type of c is 'array'.

  • Which compiler and operating system are you using? Is it a supported compiler?
    Visual Studio 2019 (v142)

  • Did you use a released version of the library or the version from the develop branch?
    A released version 3.7.0

  • If you experience a compilation error: can you compile and run the unit tests?
    This is not a compilation error.

@kyeonghopark
Copy link
Author

It can also be reproduced with:

class child : public nlohmann::json {
 public:
  explicit child(const nlohmann::json &j) : j_{j} {}

  nlohmann::json j_;
};

nlohmann::json j = nlohmann::json::parse("{\"a\":1}");
child c{j};

@kyeonghopark kyeonghopark changed the title The type of json object is set as 'array' in a constructor of an inherited class Construction in a member initializer list using curly braces is set as 'array' Sep 9, 2019
@kyeonghopark
Copy link
Author

I verified that it is not reproduced with parentheses in member initializer list:
explicit child(const nlohmann::json &j) : nlohmann::json(j) {}

It seems initialization with curly braces makes it as array.

@nlohmann
Copy link
Owner

nlohmann commented Sep 9, 2019

It seems initialization with curly braces makes it as array.

Yes, this is expected behavior for the library.

@kyeonghopark
Copy link
Author

Ok, got it.
Thanks.

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

No branches or pull requests

2 participants