mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
Ref T237, JSON functions
* container file JSON function automatically detecting JSON format (swift, cache, DB) * utility functions
This commit is contained in:
@@ -195,6 +195,42 @@ namespace BlackMisc
|
||||
return count;
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
CONTAINER IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::fromMultipleJsonFormats(const QJsonObject &jsonObject)
|
||||
{
|
||||
// also accept cache format
|
||||
if (jsonObject.isEmpty())
|
||||
{
|
||||
const CONTAINER c;
|
||||
return c;
|
||||
}
|
||||
|
||||
if (Json::looksLikeSwiftDataObject(jsonObject))
|
||||
{
|
||||
const QJsonObject cacheObj = Json::swiftDataObjectValue(jsonObject);
|
||||
// swift own format
|
||||
CONTAINER container;
|
||||
container.convertFromJson(cacheObj);
|
||||
return container;
|
||||
}
|
||||
|
||||
if (Json::looksLikeSwiftContainerJson(jsonObject))
|
||||
{
|
||||
CONTAINER container;
|
||||
container.convertFromJson(jsonObject);
|
||||
return container;
|
||||
}
|
||||
|
||||
if (jsonObject.contains("data"))
|
||||
{
|
||||
// DB format
|
||||
return IDatastoreObjectList::fromDatabaseJson(jsonObject.value("data").toArray());
|
||||
}
|
||||
|
||||
// no idea what this is
|
||||
throw CJsonException("Unsupported JSON format");
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
QDateTime IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::latestDbTimestamp() const
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKMISC_DB_DATABASEOBJECTLIST_H
|
||||
|
||||
#include "blackmisc/timestampobjectlist.h"
|
||||
#include "blackmisc/jsonexception.h"
|
||||
#include <QJsonArray>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
@@ -65,6 +66,10 @@ namespace BlackMisc
|
||||
//! Number of entries with valid DB key
|
||||
int countWithValidDbKey() const;
|
||||
|
||||
//! From multiple JSON formats
|
||||
//! \remark supports native swift C++ format, DB format, and cache format
|
||||
static CONTAINER fromMultipleJsonFormats(const QJsonObject &jsonObject);
|
||||
|
||||
//! From DB JSON with default prefixes
|
||||
//! \remark Specialized classes might have their own fromDatabaseJson implementation
|
||||
static CONTAINER fromDatabaseJson(const QJsonArray &array);
|
||||
|
||||
Reference in New Issue
Block a user