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

Deserializing std::map #1100

Closed
RolandasV opened this issue May 18, 2018 · 6 comments
Closed

Deserializing std::map #1100

RolandasV opened this issue May 18, 2018 · 6 comments
Assignees
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@RolandasV
Copy link

  • What is the issue you have?
    When trying to deserialize a std::map which has a int/Enum as a key I'm getting compilation error.
    Error C2166 l-value specifies const object

When i try to deserialize a std::map with a key as a string for example, it compiles fine.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    Serialize a std::map having int/enum as a key. Try to deserialize it.

json.at(_materialTypeByFaceSelectionJson).get<map<MaterialTypeEnum, FaceSelectionEnum>>();

  • What is the expected behavior?
    It should compile.

  • And what is the actual behavior instead?
    It doesn't.

  • Which compiler and operating system are you using? Is it a supported compiler?
    I'm using windows 10 and Visual Studio 2017.

  • Did you use a released version of the library or the version from the develop branch?
    I'm using released version.

@theodelrieu
Copy link
Contributor

There is an open PR to provide this feature: #1089

Could you try this commit and tell me if it fixes your issue?

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label May 23, 2018
@nlohmann nlohmann self-assigned this May 28, 2018
@nlohmann nlohmann added this to the Release 3.1.3 milestone May 28, 2018
@giumas
Copy link

giumas commented Jun 30, 2018

@nlohmann: since I need this feature, I am wondering if the develop branch is reliable to use it (unless 3.1.3 is coming).

@nlohmann
Copy link
Owner

I hope to release 3.1.3 before the end of July.

@giumas
Copy link

giumas commented Jul 3, 2018

If one of the map pairs (e.g., std::pair<int64_t, double>) has std::nan, it becomes a null in the written json.
If I read it back as a map, I get: [json.exception.type_error.302] type must be number, but is null.
What is the suggested approach in such a case? Should I iterate through each pair?

@giumas
Copy link

giumas commented Jul 4, 2018

@nlohmann do you prefer that I move the described issue in a stand-alone ticket?

@nlohmann
Copy link
Owner

nlohmann commented Jul 4, 2018

Yes, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

4 participants