Skip to content

Problem with serialization of my custom template doubly-linked list #1881

Description

@blazejwylegly

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) {

j = json::array();
for (Node* current = list.head; current != nullptr; current = current->getNext()) {
	nlohmann::json temp = current->getData();
	j.push_back(temp);
}

}`

(*) 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)
{

file.open("doctorList.json", std::ios::out);
if (file.good()) {
	nlohmann::json myArray = 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions