mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35: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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user