Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qserializer.pri
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DEFINES += QS_HAS_JSON

contains(DEFINES, QS_HAS_XML) {
QT += xml
}
Expand Down
16 changes: 11 additions & 5 deletions src/qserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
* version modified by Massimo Sacchi (RCH S.p.A.) to set QJsonDocument mode (setted as Compact mode)
*/

#ifndef QSERIALIZER_H
#define QSERIALIZER_H
Expand Down Expand Up @@ -49,7 +52,7 @@
#include <type_traits>
#include <QDebug>

#define QS_VERSION "1.2"
#define QS_VERSION "1.2.1"

/* Generate metaObject method */
#define QS_META_OBJECT_METHOD \
Expand All @@ -69,6 +72,9 @@ Q_DECLARE_METATYPE(QDomNode)
Q_DECLARE_METATYPE(QDomElement)
#endif

//enable QJsonDocument::Indented for readability, QJsonDocument::Compact for performance
#define QS_JSON_DOC_MODE QJsonDocument::Compact //QJsonDocument::Indented

class QSerializer {
Q_GADGET
QS_SERIALIZABLE
Expand All @@ -78,7 +84,7 @@ class QSerializer {
#ifdef QS_HAS_JSON
/*! \brief Convert QJsonValue in QJsonDocument as QByteArray. */
static QByteArray toByteArray(const QJsonValue & value){
return QJsonDocument(value.toObject()).toJson();
return QJsonDocument(value.toObject()).toJson(QS_JSON_DOC_MODE);
}
#endif

Expand Down Expand Up @@ -384,7 +390,7 @@ class QSerializer {
QJsonValue GET(json, name)() const { \
QJsonArray val; \
for(int i = 0; i < name.size(); i++) \
val.push_back(name.at(i).toJson()); \
val.push_back(name.at(i).toJson(QS_JSON_DOC_MODE)); \
return QJsonValue::fromVariant(val); \
} \
void SET(json, name)(const QJsonValue & varname) { \
Expand Down Expand Up @@ -517,7 +523,7 @@ class QSerializer {
for(auto p = name.begin(); p != name.end(); ++p) { \
val.insert( \
QVariant::fromValue(p.key()).toString(), \
p.value().toJson()); \
p.value().toJson(QS_JSON_DOC_MODE)); \
} \
return val; \
} \
Expand Down Expand Up @@ -662,7 +668,7 @@ class QSerializer {
for(auto p : name){ \
val.insert( \
QVariant::fromValue(p.first).toString(), \
p.second.toJson()); \
p.second.toJson(QS_JSON_DOC_MODE)); \
} \
return val; \
} \
Expand Down