Ref T237, JSON functions

* container file JSON function automatically detecting JSON format (swift, cache, DB)
* utility functions
This commit is contained in:
Klaus Basan
2018-01-30 06:30:39 +01:00
parent deddf7c957
commit 28b5ec9ec6
6 changed files with 55 additions and 5 deletions

View File

@@ -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
{