Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118174

Json serialization for QVariantMap is a mismatch between qt5 and qt6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.3.1
    • Core: Serialization
    • None
    • Linux/Other display system

    Description

       

      QVariantMap map = QVariantMap({ { QStringLiteral("data"), QDateTime() } });
      qDebug().noquote() << QJsonDocument::fromVariant(map).toJson(QJsonDocument::Compact);
      
      QJsonObject jo;
      jo[QStringLiteral("data")] = QJsonValue::fromVariant(QVariant(QDateTime()));
      qDebug().noquote() << QJsonDocument(jo).toJson(QJsonDocument::Compact);  

      A different output when running the code above in Qt5 and Qt6

      Output of Qt5 (5.6.0):

      {"data":null}
      {"data":null} 

      Output of Qt6 (6.3.1), expected output is the same as Qt5 but it not:

      {"data":""}
      {"data":null}

       

      I am having trouble upgrading from Qt5 to Qt6 because this change is breaking my handle.

      I have a workaround that checks whenever QDateTime is null(), then inserts QVariant().

      QVariantMap map;
      map.insert(key, date.isNull() ? QVariant() : date);

      Is there any other solution for this?

       

      *I have searched but couldn't find any documents or bugs related to this, so I created this ticket. I hope you guys will respond soon. Many thanks.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            era00 Hieu Nguyen Duy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes