Skip to content

Commit 7e9563f

Browse files
committed
Streams: Parse JSON from field
1 parent 2ebd5c5 commit 7e9563f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/app/models/key-models/stream.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <QJsonObject>
55
#include <QJsonValue>
66

7+
#include "app/jsonutils.h"
8+
79
StreamKeyModel::StreamKeyModel(
810
QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
911
int dbIndex, long long ttl)
@@ -27,7 +29,6 @@ QHash<int, QByteArray> StreamKeyModel::getRoles() {
2729

2830
QVariant StreamKeyModel::getData(int rowIndex, int dataRole) {
2931
if (!isRowLoaded(rowIndex)) return QVariant();
30-
3132
switch (dataRole) {
3233
case Value:
3334
return QJsonDocument::fromVariant(m_rowsCache[rowIndex].second)
@@ -145,7 +146,19 @@ int StreamKeyModel::addLoadedRowsToCache(const QVariantList &rows,
145146
auto valKey = valItem->toByteArray();
146147
valItem++;
147148

148-
mappedVal[valKey] = valItem->toByteArray();
149+
QByteArray fieldValue = valItem->toByteArray();
150+
151+
if (JSONUtils::isJSON(fieldValue)) {
152+
auto doc = QJsonDocument::fromJson(fieldValue);
153+
154+
if (doc.isObject() || doc.isArray()) {
155+
mappedVal[valKey] = doc.toVariant();
156+
} else {
157+
mappedVal[valKey] = fieldValue;
158+
}
159+
} else {
160+
mappedVal[valKey] = fieldValue;
161+
}
149162
}
150163

151164
value.second = mappedVal;

0 commit comments

Comments
 (0)