You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
Assuming I have some code like this
QList<QSharedPointer> aList;
QSharedPointer tmp(new SampleObject());
aList.append(tmp);
aList.append(tmp);
auto jsonarray = serializer.serialize(aList);
qDebug() << "\nSerialize a QList now:";
qDebug() << JSON_PRINT(jsonarray);
Then the generated JSON has duplicates of the object. Clearly this will not restored as intended.
The application code could use "names" or some other "ids" to prevent duplication as a workaround.
Just wondering if this has been thought of/dealt with by others.
The text was updated successfully, but these errors were encountered:
It works this way on purpose, as QObjects (which are pointers) are serialized from and to JSON. So smart pointer that wrap QObjects do the same, it just exists for convenience. Converting pointers from and to JSON is simply not possible, as you can't transform a reference.
Firstly, thanks for a great library. It's well written and super useful.
I did not expect the library to magically handle references.
Creating object references rather than duplicate objects then has to be handled at an application level as a post processing step after reading the JSON. For example, have a 64-bit ID in each QObject and do a fix-up to re-use an existing object if the ID has previously been encountered. Or something like that.
Assuming I have some code like this
QList<QSharedPointer> aList;
QSharedPointer tmp(new SampleObject());
aList.append(tmp);
aList.append(tmp);
auto jsonarray = serializer.serialize(aList);
qDebug() << "\nSerialize a QList now:";
qDebug() << JSON_PRINT(jsonarray);
Then the generated JSON has duplicates of the object. Clearly this will not restored as intended.
The application code could use "names" or some other "ids" to prevent duplication as a workaround.
Just wondering if this has been thought of/dealt with by others.
The text was updated successfully, but these errors were encountered: