Details
-
Improvement
-
Resolution: Fixed
-
Minor
-
Morpheus
-
None
-
0
Description
Nlohmann::json automatically serialises enums as integers (https://github.com/nlohmann/json?tab=readme-ov-file#specializing-enum-conversion). This is undesirable, because we often want enum values stored in JSON to be represented as strings.
To avoid the conversion to integer, we need to define custom to_json for every enum used in this way. Because of the integer-conversion behaviour is the default, it becomes easy to forget to define a to_json method for the enum, and end up with some unexpected JSON.
We can build nlohmann::json with JSON_DisableEnumSerialization=On. Since there are a few places in the code where this default behaviour is used, we have to make some changes to use an explicit static_cast<int> where the integer conversion is actually desired.