Skip to content

std::pair wrong serialization #2655

@tiregram

Description

@tiregram

What is the issue you have?

My pair is not serialized as espected and a

Please describe the steps to reproduce the issue.

std::pair<std::pair<std::string, int>, std::pair<std::string, float>> p = {
      {"a", 2}, {"a", 2}}; 
  nlohmann::json j;
  j = p;
  std::cout << j << "\n"; // i get {a:2} but i want [["a":2],["a",2]]

What is the expected behavior?

i want [["a":2],["a",2]] and not {"a":2}

And what is the actual behavior instead?

i get {"a":2} and if i serialized/deserialized, I lost my data and I get a execution error:
[json.exception.type_error.304] cannot use at() with object.

Which compiler and operating system are you using?

.

  • Compiler: gcc (GCC) 10.2.0
  • Operating system: Linux 5.4.96-1-lts

Which version of the library did you use?

  • [ x] latest release version 3.9.1

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions