We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I use templated to_json/from_json methods, because I have different serializer for the same type. I have problems with gcc with the from_json methods.
When I use the json::get method it does not compile.
#include <nlohmann/json.hpp> #include <vector> namespace ns { struct MyType { std::vector<int> i; }; template <typename json_t> void to_json(json_t &j, const MyType &m) { j["i"] = m.i; } template <typename json_t> void from_json(json_t const& j, MyType& m) { m.i = j.at("i").get<std::vector<int>>(); } } int main() { ns::MyType type; type.i.push_back(42); nlohmann::json type_json = type; ns::MyType type2 = type_json; }
As a workaround I inserted another copy: (toogle define to enable the workaround) see https://godbolt.org/z/uVW_4b
should compile
gcc error
develop
The text was updated successfully, but these errors were encountered:
Can you change
template <typename json_t> void from_json(json_t const& j, MyType& m) { m.i = j.at("i").get<std::vector<int>>(); }
to
template <typename json_t> void from_json(json_t const& j, MyType& m) { m.i = j.at("i").template get<std::vector<int>>(); }
Then it compiles for me - at least with Xcode.
Sorry, something went wrong.
Ok big thanks, this works. I always forget the template keyword. Thanks!
template
I would have missed it unless Xcode hadn't given me a hint:
No branches or pull requests
What is the issue you have?
I use templated to_json/from_json methods, because I have different serializer for the same type.
I have problems with gcc with the from_json methods.
Please describe the steps to reproduce the issue.
When I use the json::get method it does not compile.
Can you provide a small but working code example?
As a workaround I inserted another copy: (toogle define to enable the workaround)
see https://godbolt.org/z/uVW_4b
What is the expected behavior?
should compile
And what is the actual behavior instead?
gcc error
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
The text was updated successfully, but these errors were encountered: