summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsondocument.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QJsonDocument/Value: fix integer truncation in fromJson(QByteArray)Marc Mutz2025-08-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The old code passed the QByteArray's size() to the QJsonPrivate::Parser ctor's length argument, which, however, was still 'int', truncating. Making matters worse, the Parser ctor only used the length to calculate an end iterator. Fix by passing by QUtf8StringView. This also indicates that the Parser expects UTF-8 input (and not Latin1, e.g.). As a drive-by, make the Parser ctor explicit. [ChangeLog][QtCore][QJsonDocument/QJsonValue] Fixed a bug on 64-bit platforms where fromJson(QByteArray) could report one of the Unterminated errors for valid input whose size merely exceeded INT_MAX (2GiB). Amends the port of QByteArray to qsizetype (Qt 6.0, didn't check exact commit). Pick-to: 6.10 6.9 6.8 6.5 Task-number: QTBUG-103541 Change-Id: I3e4f7c098a98e8840e15ff6cc63bee2121118129 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark QJson and QCbor classes as security-criticalMarc Mutz2025-06-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These components process input external to the process, and the application depends on these components to report errors to detect failure, so these components are security-critical. The writers are, too, because a valid use of the classes is to stream-read something, filter or edit a few nodes, and then stream back, in which case writers see the same input as the readers, only in reverse, and have to build a valid output. Where there's doubt whether a header should be considered critical or not, err on the side of critical. We can always revisit the decision later when we know what semantics we'll attach to this marking. Where a header only contains declarations (and class definitions), mark as significant with reason "header, declarations only". It is probably a good idea to avoid any non-trivial inline code in headers whose .cpp files are security-critical, but moving all inline code out-of-line is a task for a different patch. Amends 8df072fc8006510c9b743e8ffedaaf51a876883a. QUIP: 23 Task-number: QTBUG-135194 Pick-to: 6.10 6.9 6.8 Change-Id: Ie317c4df652430e6e68954c37d553b760836dff8 Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
* QJson: Remove QT_JSON_READONLYThiago Macieira2025-01-171-3/+1
| | | | | | | | | | | moc (and thus the bootstrap library) has needed JSON output since Qt 5.15 (commit da284ef10e0ef80776b9fc9b7bb0e6dc8d71ba63 "Add support for machine-readable JSON output to the MOC"). Pick-to: 6.9 Change-Id: I4b8cf51c092eb35cc383fffd48d120f0cb2c56b0 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Johannes Grunenberg <nerixdev@outlook.de>
* Do not duplicate JsonFormat enumIvan Solovev2025-01-021-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | The enum already exists in QJsonDocument, so there is no reason to introduce a new one in QJsonValue. Instead, use the fact that we only need to forward-declare QJsonValue in QJsonDocument's header, include the latter into qjsonvalue.h, and use a type alias. For Qt 7, pre-program moving of the enum into QJsonValue and using an alias in QJsonDocument. Amends ac73079dee5f0260528a5c217a82cb0beafb0a56. Found in Qt 6.9 API review. [ChangeLog][QtCore][Potentially Source-Incompatible Changes] The QJsonDocument header no longer includes QJsonValue. The backward-compatible fix is to include all needed headers explicitly and to not rely on the transitive includes. Pick-to: 6.9 Change-Id: I7c5219a239149e4a87d4780c4277d111983ad0f4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QJson: Allow writing any QJsonValueJohannes Grunenberg2024-11-231-15/+3
| | | | | | | Any QJsonValue can be written as JSON now, not just objects and arrays. Change-Id: I7076ecf23091d382caab2f27bc7874c4cf0a81bd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QJson: Allow parsing any JSON value to QJsonValueJohannes Grunenberg2024-11-221-0/+5
| | | | | | | | | | | | | | | QJsonValue can now parse all its types (arrays, strings, objects, numbers, booleans, and null) at the top-level. QJsonDocument will still return an error when parsing types that aren't objects or arrays. [ChangeLog][QtCore][QJsonValue] QJsonValue now follows RFC 8259 and is thus able to parse any JSON value, not just arrays and objects. QJsonDocument remains at the level of RFC 4627 in that only arrays and objects can be parsed. Fixes: QTBUG-62502 Change-Id: I10f3895a7646953a6f6b5f132196267e700782a1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Create qdoc macros for C++ class docs 1.3: member-swap(), non-standard phrasingMarc Mutz2024-11-081-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | We have some patterns for how to document certain functions, but we also vary the sentences a lot, and you have to look up one documentation piece and copy it, essentially. If we ever want to change them, we end up with shotgun surgery. So apply DRY to the documentation and start a collection of macros to help with repetitive C++ class documentation tasks. The first macro is for member-swap(), and this third patch is for documentation that used a non-standard phrasing for documenting member-swap(). By using the macro, the documentation automatically conforms to what the documentation team picks as the \memberswap expansion going forward. As a drive-by, fix doc block indentation to the Qt standard of 4 spaces (only in changed lines), and add a few blank lines where they were missing before. Fixes: QTBUG-129573 Pick-to: 6.8 6.7 6.5 6.2 Change-Id: If007602d7690572fcbb848a8d0235416c908cfd2 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QJsonDocumentPrivate: remove unused rawData{,Size} member variablesDavid Faure2024-10-231-22/+0
| | | | | | | | | | This is a followup to commit a6b3a1e4598f829b1b60407b2e47417db6f0e442 from 2020. Found while writing gdb pretty printers for QJsonDocument and friends. Change-Id: I223751003198dc9aab3f4b108d070296bb8112db Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QJsonDocument: use new comparison helper macrosTatiana Borisova2024-03-221-9/+13
| | | | | | | | | | | | | Replace public operators operator==(), operator!=() of QJsonDocument to friend methods comparesEqual(). Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Task-number: QTBUG-120300 Change-Id: I7b61765c34406b7a9fb7dd8b1fc554c87af6a3f3 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Bootstrap: remove QVariantThiago Macieira2024-03-131-0/+2
| | | | | | | | | I added QT_NO_VARIANT to qconfig-bootstrapped.h to be clearer on what the #ifs are, but there's no testing of that feature outside of QT_BOOTSTRAPPED. Change-Id: I01ec3c774d9943adb903fffd17b7e8ac4340fb89 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Rename the JSON Save Game Example to Saving a Game to FileEdward Welbourne2023-10-201-1/+1
| | | | | | | | | | | Partly because it also saves to CBOR, but also because our guidelines say to avoid using "Example" in the title. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: Id858475a6b0474228cfe8044e188cc763f56e3a8 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Doc: Document Qt Serialization with use casesJaishree Vyas2022-12-081-0/+1
| | | | | | | | | | | Added some background about Serialization with the classes and used cases. Fixes: QTBUG-103951 Pick-to: 6.4 6.3 6.2 Change-Id: I3ff179b814fc5d424f2ac2ffaf3237b90ddd7e2b Reviewed-by: Vladimir Minenko <vladimir.minenko@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | To allow the user to customize the C++ code that QDoc sees, so as to be able to work-around some limitations on QDoc itself, QDoc defines two symbols: Q_QDOC and Q_CLANG_QDOC, both of which are "true" during an entire execution of QDoc. At a certain point in time, QDoc allowed the user the choice between a custom C++ parser and a Clang based one. The Q_QDOC symbol would always be defined while the Q_CLANG_QDOC symbol would be defined only when the Clang based parser was chosen. In more recent times, QDoc always uses a Clang based parser, such that both Q_CLANG_QDOC and Q_QDOC are always defined, making them equivalent. To avoid using different symbols, and the possible confusion and fragmentation that derives from it, all usages of Q_CLANG_QDOC are now replaced by the equivalent usages of Q_QDOC. Change-Id: I5810abb9ad1016a4c5bbea99acd03381b8514b3f Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QtBase: eradicate QT_STRINGVIEW_LEVEL usesMarc Mutz2022-07-201-2/+0
| | | | | | | | | | | | It's not used and not useful. The macro itself has to stay, for now, because Qt5Compat uses it, too. Task-number: QTBUG-100861 Pick-to: 6.4 6.3 6.2 Change-Id: I5d0557a6c959d6facf6e47f26786a9d365339e95 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-1/+1
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Core: Do not depend on transitive includesFabian Kosmale2022-03-171-0/+2
| | | | | Change-Id: I2c71188a4d27692a2d6ef1aa447b329627214b17 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Replace qt_make_unique with std::make_uniqueAllan Sandfeld Jensen2020-11-231-9/+7
| | | | | | | We can depend on C++14 now. Change-Id: Iee9796cd22dbfbb70d4bdb25f0eee1662a026d6d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Deprecate QVariant::TypeLars Knoll2020-10-231-1/+1
| | | | | | | | | It's been obsolete for a long time already. Make sure the compiler now warns about it and remove all remaining uses in qtbase. Change-Id: I0ff80311184dba52d2ba5f4e2fabe0d47fdc59d7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use qsizetype for size in QJsonArray and QJsonObjectSona Kurazyan2020-08-181-1/+1
| | | | | Change-Id: I126b7e817f076486910777bb4e3354487ad670cd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QJsonDocument: fix comparison of valid vs defaultThiago Macieira2020-08-111-1/+3
| | | | | | | | | | | [ChangeLog][QtCore][QJsonDocument] Fixed a bug that caused QJsonDocument's equality operator to crash if one of the operands was default-constructed and the other wasn't. Pick-to: 5.15 Fixes: QTBUG-85969 Change-Id: I5e00996d7f4b4a10bc98fffd1629f835f570ef6b Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Remove deprecated binary json featureEdward Welbourne2020-07-311-186/+3
| | | | | | | | | Deprecated in 5.15 in favor of CBOR. Fixes: QTBUG-81239 Change-Id: I711d4bd7dd1247f58e77ac9fa53304cbe5028918 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Clean-up methods with default values in JSON classesSona Kurazyan2020-07-261-12/+0
| | | | | | | Task-number: QTBUG-85700 Change-Id: I46e7c58e4cc94cf19cd9f11e03d2a498cd0c8922 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Fix documentation for deprecated methods in QJsonDocumentKai Koehne2020-02-281-4/+10
| | | | | | | | \deprecated has to stand on its own - qdoc will ignore anything on the right side of it. Change-Id: Ib698aa66826d6430bbafd926a9c64febd5463c5c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Replace most use of QVariant::type and occurrences of QVariant::TypeOlivier Goffart2020-01-231-5/+5
| | | | | | | | | | | | | | | | | | | | | I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Deprecate QJsonDocument methods for converting to/from JSON binarySona Kurazyan2020-01-091-2/+5
| | | | | | | | | Also remove the example code for deprecated methods and use CBOR instead where it makes sense. Task-number: QTBUG-81068 Change-Id: Iffb7a4b3d7b16a1e485fc05b3ab2e2468e9e0718 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Reimplement JSON support on top of CborUlf Hermann2019-10-211-149/+205
| | | | | | | | | | | | In turn, deprecate the QJsonDocument methods that deal with JSON binary data. You should use CBOR for data serialization these days. [ChangeLog][Deprecation Notice] The binary JSON representation is deprecated. The CBOR format should be used instead. Fixes: QTBUG-47629 Change-Id: Ic8b92ea36de87815b12307a9d8b1095f07166db8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.13' into 5.14Liang Qi2019-09-041-1/+1
|\ | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/codecs/qicucodec.cpp src/dbus/qdbusserver.cpp src/gui/painting/qbezier.cpp src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp src/plugins/printsupport/cups/qppdprintdevice.cpp Change-Id: I2703128bb64baf5580fbc2c2061b55b0f0611d2a
| * Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-08-311-1/+1
| |\ | | | | | | | | | Change-Id: I9823da32168e99bbece2f8337d0bd4d33e6d634c
| | * Doc: Clarify QJsonDocument::toJson()Joerg Bornemann2019-08-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Mention that this method returns an indented document. Change-Id: I0cadcc1c894c9a87910cfce389c6a5288238044d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* | | JSON: add some QStringView overloadsMat Sutcliffe2019-07-201-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][JSON] Added overloads of functions taking key strings as QStringView; in QJsonObject, QJsonValue and QJsonDocument. Change-Id: I78b40aba8200003acfae257ff06f5f15737005e7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* | | Move away from using 0 as a pointer constantAllan Sandfeld Jensen2019-06-071-5/+5
|/ / | | | | | | | | | | | | | | | | Cleans up most of corelib to use nullptr or default enums where appropriate. Change-Id: Ifcaac14ecdaaee730f87f10941db3ce407d71ef9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.12' into devLiang Qi2018-10-251-14/+2
|\| | | | | | | | | | | | | | | | | Conflicts: src/corelib/animation/qpropertyanimation.cpp src/gui/image/qicon.cpp tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp Change-Id: I3698172b7b44ebb487cb38f50fd2c4a9f8a35b21
| * Doc: Move literal code block to a separate fileCristian Maureira-Fredes2018-10-151-14/+2
| | | | | | | | | | | | | | | | | | | | | | We need to override this snippet for the documentation we generate for Qt for Python, and it is easier to have it on a separate file. Task-number: PYSIDE-801 Task-number: PYSIDE-691 Change-Id: Ideb5b6af25024279f167137d3b65660bb9c96a7e Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* | Handle errors when streaming QJsonDocument through QDataStreamJędrzej Nowacki2018-10-031-1/+5
| | | | | | | | | | | | Change-Id: I96df896d446e89dc4f9733a6cc6cec61a6826a1f Reviewed-by: Luca Beldi <v.ronin@yahoo.it> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Implement QJsonDocument data stream operatorsJędrzej Nowacki2018-10-031-0/+16
|/ | | | | | | Task-number: QTBUG-48313 Change-Id: I25ebeed94c9340819e925a7740bbee21de73a0ca Reviewed-by: Luca Beldi <v.ronin@yahoo.it> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Add since version for QJsonDocument::toJson()Paul Wicking2018-07-231-0/+1
| | | | | | | Task-number: QTBUG-69527 Change-Id: I10df9cc2d6fa2080e07d68b78c6220500f459380 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
* Doc: Add since version for QJson method and enumPaul Wicking2018-07-191-0/+1
| | | | | | | | | QJsonValue::toInt() introduced in 5.2, 7372c6cf9d4 QJsonDocument::JsonFormat introduced in 5.1, 4bb5566632e Task-number: QTBUG-69527 Change-Id: Idb9df959f82fe7061e0afe2109f1ca34a4451a5f Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* QJsonDocument::fromRawData: Fix out-of-bounds accessJüri Valdmann2018-05-041-0/+3
| | | | | | | | | | | | | | This method takes a pointer+size pair, but begins reading through the pointer without first checking the size parameter. Fixed by checking the size parameter. A new test case is added with an empty binary json file. Although the test does not fail under normal conditions, the problem can be detected using valgrind or AddressSanitizer. Task-number: QTBUG-61969 Change-Id: Ie91cc9a56dbc3c676472c614d4e633d7721b8481 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Create corelib/serialization and move existing file formats into itThiago Macieira2018-01-261-0/+667
This is in preparation to adding CBOR support. We don't need yet another dir for CBOR and placing it in src/corelib/json is just wrong. Change-Id: I9741f017961b410c910dfffd14ffb9d870340fa6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>