Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.6.2, 5.7.1
-
None
Description
When you initialise a QJsonObject from a QByteArray the improved "QJsonObject: Optimized equality operator" fails to match QJsonObject created dynamically through code.
This fault was found whilst evaluating 5.6.2. It was not present in 5.6.1 or previously releases since 5.2.0 (not tested on earlier releases). It appears the following commit may be responsible:
Change-Id: Ib46ee0c1008b7f114454e282b6bd2bfcdbe59e2a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
For example:
const char *message = "{\ \"brownie\": {\ \"eclair\": 1,\ \"donut\": 2\ },\ \"apple\": 3,\ \"cupcake\" : {\ \"gingerbread\": 4,\ \"froyo\": 5\ }\ }"; QJsonObject orig; QJsonParseError err; QJsonDocument jsonDoc = QJsonDocument::fromJson(QByteArray(message, strlen(message)), &err); orig = jsonDoc.object(); QJsonObject gen; gen.insert("apple", 3); QJsonObject temp1; temp1.insert("donut", 2); temp1.insert("eclair", 1); gen.insert("brownie", temp1); QJsonObject temp2; temp2.insert("froyo", 5); temp2.insert("gingerbread", 4); gen.insert("cupcake", temp2); orig == gen; // Reports false, but should report true orig.toVariantMap() == gen.toVariantMap(); // Reports true QJsonDocument().fromVariant(orig1.toVariantMap()).object() == gen; // Reports true // Note: If the external JSON is placed in alphabetical order in the test above then "orig == gen", reports true. const char *message2 = "{\ \"apple\": 3,\ \"brownie\": {\ \"donut\": 2,\ \"eclair\": 1\ },\ \"cupcake\" : {\ \"froyo\": 5,\ \"gingerbread\": 4\ }\ }"; QJsonObject orig2; QJsonParseError err2; QJsonDocument jsonDoc2 = QJsonDocument::fromJson(QByteArray(message2, strlen(message2)), &err2); orig2 = jsonDoc2.object(); orig2 == gen; // Reports true