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

Add a read-only mode when using QJsonDocument to read JSON

    XMLWordPrintable

Details

    Description

      JSON is largely used for exchanging information between server and client. The main use case of QJson module is to parse and read JSON received from the server. Therefore, most of the time, JSON is used for read-only.

      QJson module use implicit sharing. This is very important because JSON can be very large and unnecessary copying of data is very resources wasteful. However, if the developer is trying to read JSON but accidentally modify it, it could cause the data detach from QJsonDocument and create unnecessary copying of data.

      Therefore, I suggest create an enum of read-only/read-and-write mode and set the mode when using QJsonDocument::fromJSON() (and of course other similar functions) which can prevent any QJsonValue derive from the QJsonDocument can be modify (and prevent detach of data).

      Of course, accidentally modification of the JSON data can be prevent by using const for each QJsonValue derive from QJsonDocument. However, the hierarchical of JSON can be very deep and developer maybe forget to set const for QJsonValue and cause accidentally modification of JSON data.

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            dickson Dickson Leong
            Votes:
            6 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes