Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.0.0
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.