From cb1c66bd204c12d848f47de6411d31edbafaf008 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 11 Jun 2020 11:33:24 -0700 Subject: Fix conversion of QVariant() in QJsonArrays and Objects (through CBOR) When I wrote the QCborValue to QJsonValue conversion, I used QJsonValue::Undefined because it allowed to keep some level of compatibility in CBOR, despite the function documentation saying that CBOR undefineds became JSON nulls. Which they did. But when we converted QJson{Array,Object} to be backed by CBOR classes, that Undefined meant the insertion into the array/object actually deleted the entry. [ChangeLog][JSON] Fixed a regression from 5.14 that caused values of default-constructed QVariants in QVariantLists, QVariantMaps and QVariantHashes to disappear when converting to JSON via fromVariant{,List,Map,Hash}. Fixes: QTBUG-84610 Pick-to: 5.15 Change-Id: Ic0987177fe463f352db9bd84993f116e2bdacc75 Reviewed-by: Thiago Macieira --- src/corelib/serialization/qjsoncbor.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/corelib/serialization/qjsoncbor.cpp') diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp index 000008db50..8bb04fa3bf 100644 --- a/src/corelib/serialization/qjsoncbor.cpp +++ b/src/corelib/serialization/qjsoncbor.cpp @@ -280,11 +280,9 @@ QJsonValue qt_convertToJson(QCborContainerPrivate *d, qsizetype idx) return qt_convertToJson(e.flags & Element::IsContainer ? e.container : nullptr, -e.type); case QCborValue::Null: - return QJsonValue(); - case QCborValue::Undefined: case QCborValue::Invalid: - return QJsonValue::Undefined; + return QJsonValue(); case QCborValue::False: return false; @@ -375,6 +373,8 @@ QJsonValue QCborValue::toJsonValue() const return true; case Null: + case Undefined: + case Invalid: return QJsonValue(); case Double: @@ -383,10 +383,6 @@ QJsonValue QCborValue::toJsonValue() const case SimpleType: break; - case Undefined: - case Invalid: - return QJsonValue::Undefined; - case ByteArray: case String: // empty strings -- cgit v1.2.3