{"action":"closed","issue":{"url":"https://api.github.com/repos/nlohmann/json/issues/1201","repository_url":"https://api.github.com/repos/nlohmann/json","labels_url":"https://api.github.com/repos/nlohmann/json/issues/1201/labels{/name}","comments_url":"https://api.github.com/repos/nlohmann/json/issues/1201/comments","events_url":"https://api.github.com/repos/nlohmann/json/issues/1201/events","html_url":"https://github.com/nlohmann/json/issues/1201","id":351820263,"node_id":"MDU6SXNzdWUzNTE4MjAyNjM=","number":1201,"title":"Subclassing json() & error on recursive load","user":{"login":"Dariusz1989","id":13185728,"node_id":"MDQ6VXNlcjEzMTg1NzI4","avatar_url":"https://avatars0.githubusercontent.com/u/13185728?v=4","gravatar_id":"","url":"https://api.github.com/users/Dariusz1989","html_url":"https://github.com/Dariusz1989","followers_url":"https://api.github.com/users/Dariusz1989/followers","following_url":"https://api.github.com/users/Dariusz1989/following{/other_user}","gists_url":"https://api.github.com/users/Dariusz1989/gists{/gist_id}","starred_url":"https://api.github.com/users/Dariusz1989/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dariusz1989/subscriptions","organizations_url":"https://api.github.com/users/Dariusz1989/orgs","repos_url":"https://api.github.com/users/Dariusz1989/repos","events_url":"https://api.github.com/users/Dariusz1989/events{/privacy}","received_events_url":"https://api.github.com/users/Dariusz1989/received_events","type":"User","site_admin":false},"labels":[{"id":344572510,"node_id":"MDU6TGFiZWwzNDQ1NzI1MTA=","url":"https://api.github.com/repos/nlohmann/json/labels/state:%20help%20needed","name":"state: help needed","color":"fbca04","default":false},{"id":730407699,"node_id":"MDU6TGFiZWw3MzA0MDc2OTk=","url":"https://api.github.com/repos/nlohmann/json/labels/state:%20stale","name":"state: stale","color":"999999","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-08-18T13:26:30Z","updated_at":"2018-11-05T19:02:38Z","closed_at":"2018-11-05T19:02:38Z","author_association":"NONE","body":"Hey\r\n\r\nSo I have subclassed json with another class so that in future if I want to change the container class/type I can just replace that within my class and not have to go over entire app replacing all containers.\r\n\r\nEssentially class looks like this :  \r\n\r\n```cpp\r\nclass myObject : public json {\r\npublic:\r\n    myObject(){};\r\n    ~myObject() {};\r\n    friend QDebug operator<<(QDebug stream, const myObject &metaData);\r\n};\r\nQ_DECLARE_METATYPE(myObject);\r\n```\r\n\r\nNow the issue is when I have a json file I read from file, that has some name/id/etc information + children which is of the same structure.\r\n\r\nThe initial object load file, but the children throw me an error. \r\n\r\nSay if I do\r\ndata[\"name] < this prints name.\r\nif I do data[\"children\"].count() < this gets me proper count\r\nif I do data[\"children\"][0][\"name] < this gets me name of child - all great.\r\n\r\nBut if I try to pass that object to newly created class to configure it. Say child class I get this error : \r\nEssentially loops goes as follow:\r\n\r\n```cpp\r\nvoid objectTemplate::setData(myObject data) {\r\n\tmName = data[\"name\"].get<std::string>();\r\n\tfor (int x = 0; x < data[\"children\"].size(); ++x) {\r\n\t\tstd::cout << \"sending child to be generated\" << data[\"children\"][x];\r\n\t\tmyTempalte objectTemplate;\r\n\t\tobjectTemplate.setData(data[\"children\"][x]); /// this errors out here\r\n\t\tmChildTemplates.push_back(objectTemplate);\r\n\t}\r\n}\r\n```\r\n\r\nErrors starts here: \r\n\r\n```cpp\r\nvoid from_json(const BasicJsonType& j, CompatibleArrayType& arr)\r\n{\r\n\tif (JSON_UNLIKELY(not j.is_array()))\r\n\t{\r\n\t\tJSON_THROW(type_error::create(302, \"type must be array, but is \" +\r\n\t\t\tstd::string(j.type_name())));\r\n\t}\r\n\r\n\tfrom_json_array_impl(j, arr, priority_tag<2> {});\r\n}\r\n```\r\n\r\nIts driving me nuts, as far as I debug it, everything is of proper myObject class & have data whenever I print it. But the second I try to generate child from json[\"children\"]array I get an crash :- (\r\n\r\nDoes this look familiar to any one? \r\n\r\nTIA\r\nBtw I have no idea why formating is off ;[\r\n\r\nEdit1. Thanks Nlohmann for formating fix! : -)\r\nI also did test with using json, instead of myObject class and everyhing works. So there is a weird issue when I try to load children as my subclass class thini ? "}}
{"actor":{"display_login":"stale"}}