4#ifndef SERIALIZABLEJSONLIST_H
5#define SERIALIZABLEJSONLIST_H
8#include "iserializabletojson.h"
9#include "ideserializablefromjson.h"
29 static_assert(std::is_base_of<ISerializableToJsonObject, T>::value,
"T not derived from ISerializableToJsonObject");
30 for(
typename QList<T>::const_iterator it = this->constBegin();it != this->constEnd();it++) {
34 jsonArray.append(obj);
47 static_assert(std::is_base_of<IDeserializableFromJsonObject, T>::value,
"T not derived from IDeserializableFromJsonObject");
48 for(
const QJsonValue& jsonValue : jsonArray) {
73 static_assert(std::is_base_of<ISerializableToJsonObject, T>::value,
"T not derived from ISerializableToJsonObject");
74 for(
typename QList<QSharedPointer<T>>::const_iterator it = this->constBegin();it != this->constEnd();it++) {
75 QSharedPointer<T> item = *it;
76 QSharedPointer<ISerializableToJsonObject> ptr = qSharedPointerCast<ISerializableToJsonObject>(item);
77 QJsonObject obj = ptr->serializeToJsonObject();
78 jsonArray.append(obj);
88 static_assert(std::is_base_of<IDeserializableFromJsonObject, T>::value,
"T not derived from IDeserializableFromJsonObject");
89 for(
const QJsonValue& jsonValue : jsonArray) {
90 QSharedPointer<T> item(
new T());
91 QSharedPointer<IDeserializableFromJsonObject> ptr = qSharedPointerCast<IDeserializableFromJsonObject>(item);
92 ptr->deserializeFromJsonObject(jsonValue.toObject());
Interface for objects that can deserialize themselves from a QJsonObject.
virtual void deserializeFromJsonObject(const QJsonObject &jsonObject)=0
Populate this object from a QJsonObject.
Interface for objects that can serialize themselves into a QJsonObject, with JSON helper utilities.
virtual QJsonObject serializeToJsonObject() const =0
Serialize this object into a QJsonObject.
Template helpers for serializing and deserializing lists of JSON-capable objects.
QJsonArray serializeToJsonArray() const
Serialize all elements to a QJsonArray.
void deserializeFromJsonArray(const QJsonArray &jsonArray)
Populate this list by deserializing each element of a QJsonArray.
A QList of QSharedPointer<T> that serializes/deserializes its elements via ISerializableToJsonObject.
QJsonArray serializeToJsonArray() const
Serialize all elements to a QJsonArray.
void deserializeFromJsonArray(const QJsonArray &jsonArray)
Populate this list by deserializing each element of a QJsonArray.