-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Problem with serialization of my custom template doubly-linked list #1881
Comments
You need to implement a free function |
Sadly I don't think, that I understand what do you mean by "Free function". I've tried to follow the guide you have linked before posting the issue. I've implemented to_json function for both Doctor and List, similiar to those presented in documentation. I assume, that my List::to_json(...) function is not visible in other files. What am I missing? |
It must not be a member function. |
I think i've understood in correctly, but im still struggling to solve this. Here's what ive got so far:
void toJson(nlohmann::json& j, const List< T >& list)
void JsonWriter::saveDoctorList(const List& doc){ Line When I try to test same functionality for Doctor in main.cpp I suppose that my problem is trivial but i can't get over it. Btw. sorry for poor code pasting. |
Please have a look at the README. The function must be called |
Oh... I completely missed it. Didn't think of it at all. Changing function name solved problem. Thank you for your time @nlohmann . |
Im trying to write a function responsible for saving my custom list into json file.
The list i want to save into file consists of Node objects (Node is inner class of List). The list i need to save uses Doctor objects as T ( List is template class defined in single header file).
Following the guide, I've implemented toJson method for Doctor, and toJson method for my list:
`
template < class T >
void List::toJson(nlohmann::json& j, const List< T >& list) {
}`
(*) getData() method returns reference to Doctor object stored in Node.
Now, in separate class JsonWriter i use method (List.h is included in JsonWriter.h)
void JsonWriter::saveDoctorList(const List< Doctor >& doctorList)
{
}'
...and that's the point where i get stuck. Inside if statement, the compilers signals that
"no suitable user-defined conversion from "const List< Doctor >" to "nlohmann::json" exists".
When i try to do the same
nlohmann::json myArray = doctorList;
inside my List.h file it compiles without an error.I've tried to find solution on both github and StackOverflow. I've also looked through issues here, but I can't find anything that solves my problems. Can anybody tell me what am I missing?
Using VS 2017 and Windows
Thanks for any suggestions.
The text was updated successfully, but these errors were encountered: