-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
Hey
So 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.
Essentially class looks like this :
class myObject : public json {
public:
myObject(){};
~myObject() {};
friend QDebug operator<<(QDebug stream, const myObject &metaData);
};
Q_DECLARE_METATYPE(myObject);Now 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.
The initial object load file, but the children throw me an error.
Say if I do
data["name] < this prints name.
if I do data["children"].count() < this gets me proper count
if I do data["children"][0]["name] < this gets me name of child - all great.
But if I try to pass that object to newly created class to configure it. Say child class I get this error :
Essentially loops goes as follow:
void objectTemplate::setData(myObject data) {
mName = data["name"].get<std::string>();
for (int x = 0; x < data["children"].size(); ++x) {
std::cout << "sending child to be generated" << data["children"][x];
myTempalte objectTemplate;
objectTemplate.setData(data["children"][x]); /// this errors out here
mChildTemplates.push_back(objectTemplate);
}
}Errors starts here:
void from_json(const BasicJsonType& j, CompatibleArrayType& arr)
{
if (JSON_UNLIKELY(not j.is_array()))
{
JSON_THROW(type_error::create(302, "type must be array, but is " +
std::string(j.type_name())));
}
from_json_array_impl(j, arr, priority_tag<2> {});
}Its 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 :- (
Does this look familiar to any one?
TIA
Btw I have no idea why formating is off ;[
Edit1. Thanks Nlohmann for formating fix! : -)
I 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 ?