Skip to content

Error thrown when parsing in a subclass #2124

Description

@paulaltin
  • What is the issue you have?

When I create an instance of a subclass of nlohmann::json, attempting to deserialize a string to it using json::parse throws an error.

  • Please describe the steps to reproduce the issue.

Given:

class json_subclass : public json {};

then the following all work as expected:

json a = "{}"_json;
json b(json::parse("{}"));
json c = json::parse("{}");
json d; d = json::parse("{}");

but any of the following throw an error:

json_subclass a = "{}"_json;
json_subclass b(json::parse("{}"));
json_subclass c = json::parse("{}");
json_subclass d; d = json::parse("{}");

The error thrown is [json.exception.type_error.302] type must be array, but is object.

  • What is the expected behavior?

Deserializing a string to a nlohmann::json subclass should work.

  • And what is the actual behavior instead?

An error is thrown: [json.exception.type_error.302] type must be array, but is object.

  • Which compiler and operating system are you using?

Mac OS X 10.14.6
Xcode 11.3.1 (11C505)
Apple clang version 11.0.0 (clang-1100.0.33.17)

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

Release 3.7.3.

  • Other notes

This may be related to issue #608, although I'm unable to reproduce the exact problem described there.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions