Serialization of std::map<std::pair<std::string, std::string>, std::vector<std::string>> is inconsistent? #4013
-
Given the following code:
Why does the output change if the value of the set only has two items?
I even inserted the two items for A one at a time with push_back, but still saw the same result. Is this a bug, or am I just doing something improperly? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Using anything other than string as the key of the map results in some interesting interpretations. See the constructor documentation about interpreting collections as name value pairs vs plain arrays of values. https://json.nlohmann.me/api/basic_json/basic_json/ |
Beta Was this translation helpful? Give feedback.
-
I think the actual issue here stems from Item 5b on https://json.nlohmann.me/api/basic_json/basic_json/
Since the keys are pairs of strings and the value is a string vector, if it has exactly 2 items, then it fulfills the above requirement and is treated differently. I intend to switch to another JSON library but, in the meanwhile, I simply added code during my JSON Read/Write functions that adds/removes a 3rd temporary item to any of the value vectors that only have two items. |
Beta Was this translation helpful? Give feedback.
I think the actual issue here stems from Item 5b on https://json.nlohmann.me/api/basic_json/basic_json/
Since the keys are pairs of strings and the value is a string vector, if it has exactly 2 items, then it fulfills the above requirement and is treated differently.
I intend to switch to another JSON library but, in the meanwhile, I simply added code during my JSON Read/Write functions that adds/removes a 3rd temporary item to any of the value vectors that only have two items.