Allow registering lists of ThingId on json rpc

This commit is contained in:
Michael Zanetti 2022-11-12 23:59:25 +01:00
parent 8367f60886
commit 289362fefc

View File

@ -208,7 +208,7 @@ void JsonHandler::registerObject(const QMetaObject &metaObject)
typeName = QString("$ref:BasicType");
} else if (QString(metaProperty.typeName()).startsWith("QList")) {
QString elementType = QString(metaProperty.typeName()).remove("QList<").remove(">");
if (elementType == "EventTypeId" || elementType == "StateTypeId" || elementType == "ActionTypeId") {
if (elementType == "ThingId" || elementType == "EventTypeId" || elementType == "StateTypeId" || elementType == "ActionTypeId") {
elementType = "QUuid";
}
QVariant::Type variantType = QVariant::nameToType(elementType.toUtf8());
@ -349,6 +349,10 @@ QVariant JsonHandler::pack(const QMetaObject &metaObject, const void *value) con
foreach (const QUuid &entry, propertyValue.value<QList<QUuid>>()) {
list << entry;
}
} else if (propertyTypeName == "QList<ThingId>") {
foreach (const ThingId &entry, propertyValue.value<QList<ThingId>>()) {
list << entry;
}
} else if (propertyTypeName == "QList<EventTypeId>") {
foreach (const EventTypeId &entry, propertyValue.value<QList<EventTypeId>>()) {
list << entry;
@ -477,6 +481,7 @@ QVariant JsonHandler::unpack(const QMetaObject &metaObject, const QVariant &valu
}
metaProperty.writeOnGadget(ptr, QVariant::fromValue(intList));
} else if (metaProperty.typeName() == QStringLiteral("QList<QUuid>")
|| metaProperty.typeName() == QStringLiteral("QList<ThingId>")
|| metaProperty.typeName() == QStringLiteral("QList<EventTypeId>")
|| metaProperty.typeName() == QStringLiteral("QList<StateTypeId>")
|| metaProperty.typeName() == QStringLiteral("QList<ActionTypeId>")) {