Replies: 1 comment 1 reply
-
I had the same issue, and adding this macro seems to fix it. /*!
@brief macro added to work with ordered_json -- hutch
@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_UNORDERED
*/
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_UNORDERED(Type, ...) \
inline void to_json(nlohmann::ordered_json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const nlohmann::ordered_json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is the issue you have?
When using the macros suggested here to automatically create serialization methods for structs, to_json is only defined with a concrete
json
type.Please describe the steps to reproduce the issue.
Can you provide a small but working code example?
What is the expected behavior?
The assignment to the ordered_json should behave in the same way as assignment to json.
And what is the actual behavior instead?
The code snippet does not compile when the commented line is used.
Workaround
Define to_json and from_json manually:
Or use this macro instead:
Suggested fix
Either add ordered_json overloads in the macro itself, or possibly do some template magic to use basic_json in the parameter list.
Less ideal fix
Add a new macro specific to ordered_json
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchP.S. Love the library :)
Beta Was this translation helpful? Give feedback.
All reactions