QtJsonSerializer  4.0.0
A library to perform generic seralization and deserialization of QObjects
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
QtJsonSerializer::JsonSerializer Class Reference

A class to serialize and deserialize c++ classes to and from JSON. More...

#include <jsonserializer.h>

+ Inheritance diagram for QtJsonSerializer::JsonSerializer:

Public Types

enum  ByteArrayFormat { ByteArrayFormat::Base64, ByteArrayFormat::Base64url, ByteArrayFormat::Base16 }
 Defines the different supported bytearray formats. More...
 
- Public Types inherited from QtJsonSerializer::SerializerBase
enum  ValidationFlag {
  ValidationFlag::StandardValidation = 0x00, ValidationFlag::NoExtraProperties = 0x01, ValidationFlag::AllProperties = 0x02, ValidationFlag::StrictBasicTypes = 0x04,
  ValidationFlag::FullPropertyValidation = (NoExtraProperties | AllProperties), ValidationFlag::FullValidation = (FullPropertyValidation | StrictBasicTypes)
}
 Flags to specify how strict the serializer should validate when deserializing. More...
 
enum  Polymorphing { Polymorphing::Disabled, Polymorphing::Enabled, Polymorphing::Forced }
 Enum to specify the modes of polymorphism. More...
 
enum  MultiMapMode { MultiMapMode::Map, MultiMapMode::List, MultiMapMode::DenseMap }
 Enum to specify how multi maps and sets should be serialized. More...
 

Public Slots

void setByteArrayFormat (ByteArrayFormat byteArrayFormat)
 WRITE accessor for QJsonSerializer::byteArrayFormat.
 
void setValidateBase64 (bool validateBase64)
 WRITE accessor for QJsonSerializer::validateBase64.
 
- Public Slots inherited from QtJsonSerializer::SerializerBase
void setAllowDefaultNull (bool allowDefaultNull)
 WRITE accessor for QJsonSerializer::allowDefaultNull.
 
void setKeepObjectName (bool keepObjectName)
 WRITE accessor for QJsonSerializer::keepObjectName.
 
void setEnumAsString (bool enumAsString)
 WRITE accessor for QJsonSerializer::enumAsString.
 
void setVersionAsString (bool versionAsString)
 WRITE accessor for QJsonSerializer::versionAsString.
 
void setDateAsTimeStamp (bool dateAsTimeStamp)
 WRITE accessor for QJsonSerializer::dateAsTimeStamp.
 
void setUseBcp47Locale (bool useBcp47Locale)
 WRITE accessor for QJsonSerializer::useBcp47Locale.
 
void setValidationFlags (ValidationFlags validationFlags)
 WRITE accessor for QJsonSerializer::validationFlags.
 
void setPolymorphing (Polymorphing polymorphing)
 WRITE accessor for QJsonSerializer::polymorphing.
 
void setMultiMapMode (MultiMapMode multiMapMode)
 WRITE accessor for QJsonSerializer::multiMapMode.
 
void setIgnoreStoredAttribute (bool ignoreStoredAttribute)
 WRITE accessor for QJsonSerializer::ignoreStoredAttribute.
 

Signals

void byteArrayFormatChanged (ByteArrayFormat byteArrayFormat, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::byteArrayFormat.
 
void validateBase64Changed (bool validateBase64, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::validateBase64.
 
- Signals inherited from QtJsonSerializer::SerializerBase
void allowDefaultNullChanged (bool allowDefaultNull, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::allowDefaultNull.
 
void keepObjectNameChanged (bool keepObjectName, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::keepObjectName.
 
void enumAsStringChanged (bool enumAsString, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::enumAsString.
 
void versionAsStringChanged (bool versionAsString, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::versionAsString.
 
void dateAsTimeStampChanged (bool dateAsTimeStamp, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::dateAsTimeStamp.
 
void useBcp47LocaleChanged (bool useBcp47Locale, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::useBcp47Locale.
 
void validationFlagsChanged (ValidationFlags validationFlags, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::validationFlags.
 
void polymorphingChanged (Polymorphing polymorphing, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::polymorphing.
 
void multiMapModeChanged (MultiMapMode multiMapMode, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::multiMapMode.
 
void ignoreStoredAttributeChanged (bool ignoreStoredAttribute, QPrivateSignal)
 NOTIFY accessor for QJsonSerializer::ignoreStoredAttribute.
 

Public Member Functions

 JsonSerializer (QObject *parent=nullptr)
 Default constructor.
 
QJsonValue serialize (const QVariant &data) const
 Serializers a QVariant value to a QJsonValue. More...
 
void serializeTo (QIODevice *device, const QVariant &data, QJsonDocument::JsonFormat format=QJsonDocument::Compact) const
 Serializers a QVariant value to a device. More...
 
QByteArray serializeTo (const QVariant &data, QJsonDocument::JsonFormat format=QJsonDocument::Compact) const
 Serializers a QVariant value to a byte array. More...
 
template<typename T >
QtJsonSerializer::__private::json_type< T >::type serialize (const T &data) const
 Serializers a generic c++ type to json. More...
 
template<typename T >
void serializeTo (QIODevice *device, const T &data, QJsonDocument::JsonFormat format=QJsonDocument::Compact) const
 Serializers a generic c++ type to a device. More...
 
template<typename T >
QByteArray serializeTo (const T &data, QJsonDocument::JsonFormat format=QJsonDocument::Compact) const
 Serializers a generic c++ type to a byte array. More...
 
QVariant deserialize (const QJsonValue &json, int metaTypeId, QObject *parent=nullptr) const
 Deserializes a QJsonValue to a QVariant value, based on the given type id. More...
 
QVariant deserializeFrom (QIODevice *device, int metaTypeId, QObject *parent=nullptr) const
 Deserializes data from a device to a QVariant value, based on the given type id. More...
 
QVariant deserializeFrom (const QByteArray &data, int metaTypeId, QObject *parent=nullptr) const
 Deserializes data from a device to a QVariant value, based on the given type id. More...
 
template<typename T >
deserialize (const typename QtJsonSerializer::__private::json_type< T >::type &json, QObject *parent=nullptr) const
 Deserializes a json to the given c++ type. More...
 
template<typename T >
deserializeFrom (QIODevice *device, QObject *parent=nullptr) const
 Deserializes data from a device to the given c++ type. More...
 
template<typename T >
deserializeFrom (const QByteArray &data, QObject *parent=nullptr) const
 Deserializes data from a byte array to the given c++ type. More...
 
ByteArrayFormat byteArrayFormat () const
 READ accessor for QJsonSerializer::byteArrayFormat.
 
bool validateBase64 () const
 READ accessor for QJsonSerializer::validateBase64.
 
std::variant< QCborValue, QJsonValueserializeGeneric (const QVariant &value) const override
 Serializes a given variant to either CBOR or JSON, depending on the actual instance. More...
 
QVariant deserializeGeneric (const std::variant< QCborValue, QJsonValue > &value, int metaTypeId, QObject *parent) const override
 Deserializes CBOR or JSON, depending on the actual instance, to variant. More...
 
- Public Member Functions inherited from QtJsonSerializer::SerializerBase
bool allowDefaultNull () const
 READ accessor for QJsonSerializer::allowDefaultNull.
 
bool keepObjectName () const
 READ accessor for QJsonSerializer::keepObjectName.
 
bool enumAsString () const
 READ accessor for QJsonSerializer::enumAsString.
 
bool versionAsString () const
 READ accessor for QJsonSerializer::versionAsString.
 
bool dateAsTimeStamp () const
 READ accessor for QJsonSerializer::dateAsTimeStamp.
 
bool useBcp47Locale () const
 READ accessor for QJsonSerializer::useBcp47Locale.
 
ValidationFlags validationFlags () const
 READ accessor for QJsonSerializer::validationFlags.
 
Polymorphing polymorphing () const
 READ accessor for QJsonSerializer::polymorphing.
 
MultiMapMode multiMapMode () const
 READ accessor for QJsonSerializer::multiMapMode.
 
bool ignoresStoredAttribute () const
 READ accessor for QJsonSerializer::ignoreStoredAttribute.
 
template<typename TConverter >
void addJsonTypeConverter ()
 Adds a custom type converter to this serializer. More...
 
void addJsonTypeConverter (const QSharedPointer< TypeConverter > &converter)
 Adds a custom type converter to this serializer. More...
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 Q_CLASSINFO (Name, Value)
 
 Q_INTERFACES (...)
 
 Q_PROPERTY (...)
 
 Q_ENUMS (...)
 
 Q_FLAGS (...)
 
 Q_ENUM (...)
 
 Q_FLAG (...)
 
 Q_ENUM_NS (...)
 
 Q_FLAG_NS (...)
 
 Q_OBJECT Q_OBJECT
 
 Q_GADGET Q_GADGET
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SLOTS Q_SLOTS
 
 Q_SLOT Q_SLOT
 
 Q_EMIT Q_EMIT
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 

Protected Member Functions

bool jsonMode () const override
 Returns true, if de/serializing to JSON, and false for CBOR.
 
QCborTag typeTag (int metaTypeId) const override
 Returns a tag registered for the given metaTypeId.
 
QList< int > typesForTag (QCborTag tag) const override
 
- Protected Member Functions inherited from QtJsonSerializer::SerializerBase
 SerializerBase (QObject *parent=nullptr)
 Default constructor.
 
QVariant getProperty (const char *name) const override
 Returns a property from the serializer.
 
QSharedPointer< const TypeExtractorextractor (int metaTypeId) const override
 Returns a reference to an extractor for the given type, or nullptr.
 
QCborValue serializeSubtype (const QMetaProperty &property, const QVariant &value) const override
 Serialize a subvalue, represented by a meta property.
 
QCborValue serializeSubtype (int propertyType, const QVariant &value, const QByteArray &traceHint) const override
 Serialize a subvalue, represented by a type id.
 
QVariant deserializeSubtype (const QMetaProperty &property, const QCborValue &value, QObject *parent) const override
 Deserialize a subvalue, represented by a meta property.
 
QVariant deserializeSubtype (int propertyType, const QCborValue &value, QObject *parent, const QByteArray &traceHint) const override
 Deserialize a subvalue, represented by a type id.
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Properties

ByteArrayFormat byteArrayFormat
 Specifies the format, in which bytearray should be converter to a JSON string. More...
 
bool validateBase64
 Specify whether deserializing a QByteArray should verify the data as base64 instead of silent discarding. More...
 
- Properties inherited from QtJsonSerializer::SerializerBase
bool allowDefaultNull
 Specifies whether null for value types is allowed or not. More...
 
bool keepObjectName
 Specifies whether the objectName property of QObjects should be serialized. More...
 
bool enumAsString
 Specifies whether enums should be serialized as integer or as string. More...
 
bool versionAsString
 Specifies whether enums should be serialized as array of integers or as string. More...
 
bool dateAsTimeStamp
 Specifies whether datetimes should be serialized as datetime string or as unix timestamp. More...
 
bool useBcp47Locale
 Specifies whether serializing a QLocale should use the bcp47 format. More...
 
ValidationFlags validationFlags
 Specifies how strictly the serializer should verify data when deserializing. More...
 
Polymorphing polymorphing
 Specifies how the serializer should treat polymorphism for QObject classes. More...
 
MultiMapMode multiMapMode
 Specifies how multi maps and sets should be serialized. More...
 
bool ignoreStoredAttribute
 Specifies whether the STORED attribute on properties has any effect.
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Member Functions inherited from QtJsonSerializer::SerializerBase
template<typename TType , typename TExtractor >
static void registerExtractor ()
 Registers a custom extractor for the given type. More...
 
static void registerExtractor (int metaTypeId, const QSharedPointer< TypeExtractor > &extractor)
 Registers a custom extractor for the given type. More...
 
template<typename T >
static void registerListConverters ()
 Registers a custom type for list converisons. More...
 
template<typename T >
static void registerSetConverters ()
 Registers a custom type for set converisons. More...
 
template<typename TKey , typename TValue , bool mapTypes = true, bool hashTypes = true>
static void registerMapConverters ()
 Registers a custom type for map converisons. More...
 
template<typename T >
static void registerPointerConverters ()
 Registers a custom type for QSharedPointer and QPointer converisons. More...
 
template<typename T >
static void registerBasicConverters ()
 Registers a custom type for list, set map and optional converisons. Also include pointer converters, if applicable. More...
 
template<typename T , typename U >
static void registerPairConverters ()
 Registers two types for pair conversion. More...
 
template<typename... TArgs>
static void registerTupleConverters ()
 Registers a number of types for std::tuple conversion. More...
 
template<typename T >
static void registerOptionalConverters ()
 Registers a custom type for std::optional converisons. More...
 
template<typename... TArgs>
static void registerVariantConverters ()
 Registers a custom type for std::variant converisons. More...
 
template<typename TConverter , int Priority = TypeConverter::Priority::Standard>
static void addJsonTypeConverterFactory ()
 Globally registers a converter factory to provide converters for all QJsonSerializer instances. More...
 
static void addJsonTypeConverterFactory (TypeConverterFactory *factory)
 Globally registers a converter factory to provide converters for all QJsonSerializer instances. More...
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

A class to serialize and deserialize c++ classes to and from JSON.

This class is one of the modules core component. It performs the de/serialization of C++ classes from and to JSON.

Supported types

The serializer supports a bunch of types by default, but there are limitations. Check the main page Usage Hints for details about what is possible and what is not.

Extending the serializer

To extend the serializers functionality, create a custom implementation of the TypeConverter class. Check it's documentation for more details and an example on how to. Once you've created a custom converter class, you can add it to a serializer instance by using SerializerBase::addJsonTypeConverter.

See also
SerializerBase, CborSerializer

Definition at line 15 of file jsonserializer.h.

Member Enumeration Documentation

◆ ByteArrayFormat

Defines the different supported bytearray formats.

Enumerator
Base64 

Data is encoded as base64 string with padding.

Base64url 

Data is encoded as base64url string, without padding.

Base16 

Data is encoded as hexadecimal string (any case)

Definition at line 26 of file jsonserializer.h.

Member Function Documentation

◆ deserialize() [1/2]

QtJsonSerializer::JsonSerializer::deserialize ( const QJsonValue json,
int  metaTypeId,
QObject parent = nullptr 
) const

Deserializes a QJsonValue to a QVariant value, based on the given type id.

Parameters
jsonThe data to be deserialized
metaTypeIdThe target type of the deserialization
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value, wrapped in QVariant
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
JsonSerializer::serialize, JsonSerializer::deserializeFrom

◆ deserialize() [2/2]

template<typename T >
QtJsonSerializer::JsonSerializer::deserialize ( const typename QtJsonSerializer::__private::json_type< T >::type &  json,
QObject parent = nullptr 
) const

Deserializes a json to the given c++ type.

Template Parameters
TThe type of the data to be deserialized
Parameters
jsonThe data to be deserialized
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
JsonSerializer::serialize, JsonSerializer::deserializeFrom

Definition at line 124 of file jsonserializer.h.

◆ deserializeFrom() [1/4]

QtJsonSerializer::JsonSerializer::deserializeFrom ( const QByteArray data,
int  metaTypeId,
QObject parent = nullptr 
) const

Deserializes data from a device to a QVariant value, based on the given type id.

Parameters
dataThe data to read the json to be deserialized from
metaTypeIdThe target type of the deserialization
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value, wrapped in QVariant
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
JsonSerializer::serializeTo, JsonSerializer::deserialize

◆ deserializeFrom() [2/4]

template<typename T >
QtJsonSerializer::JsonSerializer::deserializeFrom ( const QByteArray data,
QObject parent = nullptr 
) const

Deserializes data from a byte array to the given c++ type.

Template Parameters
TThe type of the data to be deserialized
Parameters
dataThe data to read the json to be deserialized from
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
JsonSerializer::serializeTo, JsonSerializer::deserialize

Definition at line 138 of file jsonserializer.h.

◆ deserializeFrom() [3/4]

QtJsonSerializer::JsonSerializer::deserializeFrom ( QIODevice device,
int  metaTypeId,
QObject parent = nullptr 
) const

Deserializes data from a device to a QVariant value, based on the given type id.

Parameters
deviceThe device to read the json to be deserialized from
metaTypeIdThe target type of the deserialization
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value, wrapped in QVariant
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
JsonSerializer::JsonSerializer::serializeTo, JsonSerializer::deserialize

◆ deserializeFrom() [4/4]

template<typename T >
QtJsonSerializer::JsonSerializer::deserializeFrom ( QIODevice device,
QObject parent = nullptr 
) const

Deserializes data from a device to the given c++ type.

Template Parameters
TThe type of the data to be deserialized
Parameters
deviceThe device to read the json to be deserialized from
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
JsonSerializer::serializeTo, JsonSerializer::deserialize

Definition at line 131 of file jsonserializer.h.

◆ deserializeGeneric()

QVariant QtJsonSerializer::JsonSerializer::deserializeGeneric ( const std::variant< QCborValue, QJsonValue > &  value,
int  metaTypeId,
QObject parent 
) const
overridevirtual

Deserializes CBOR or JSON, depending on the actual instance, to variant.

Parameters
valueThe CBOR/JSON data to be deserialized
metaTypeIdThe target type of the deserialization
parentThe parent object of the result. Only used if the returend value is a QObject*
Returns
The deserialized value, wrapped in QVariant
Exceptions
DeserializationExceptionThrown if the deserialization fails
See also
SerializerBase::serializeGeneric, JsonSerializer::deserialize, CborSerializer::deserialize

Implements QtJsonSerializer::SerializerBase.

◆ serialize() [1/2]

QtJsonSerializer::JsonSerializer::serialize ( const QVariant data) const

Serializers a QVariant value to a QJsonValue.

Parameters
dataThe data to be serialized
Returns
The serialized value
Exceptions
SerializationExceptionThrown if the serialization fails
See also
JsonSerializer::deserialize, JsonSerializer::serializeTo

◆ serialize() [2/2]

template<typename T >
QtJsonSerializer::JsonSerializer::serialize ( const T &  data) const

Serializers a generic c++ type to json.

Template Parameters
TThe type of the data to be serialized
Parameters
dataThe data to be serialized
Returns
The serialized value
Exceptions
SerializationExceptionThrown if the serialization fails
See also
JsonSerializer::deserialize, JsonSerializer::serializeTo

Definition at line 103 of file jsonserializer.h.

◆ serializeGeneric()

std::variant<QCborValue, QJsonValue> QtJsonSerializer::JsonSerializer::serializeGeneric ( const QVariant value) const
overridevirtual

Serializes a given variant to either CBOR or JSON, depending on the actual instance.

Parameters
valueThe data to be serialized
Returns
The serialized value
Exceptions
SerializationExceptionThrown if the serialization fails
See also
SerializerBase::deserializeGeneric, JsonSerializer::serialize, CborSerializer::serialize

Implements QtJsonSerializer::SerializerBase.

◆ serializeTo() [1/4]

QtJsonSerializer::JsonSerializer::serializeTo ( const QVariant data,
QJsonDocument::JsonFormat  format = QJsonDocument::Compact 
) const

Serializers a QVariant value to a byte array.

Parameters
dataThe data to be serialized
formatThe formatting for the generated json (compact or intended)
Returns
The serialized data as byte array
Exceptions
SerializationExceptionThrown if the serialization fails
See also
JsonSerializer::deserializeFrom, JsonSerializer::serialize

◆ serializeTo() [2/4]

template<typename T >
QtJsonSerializer::JsonSerializer::serializeTo ( const T &  data,
QJsonDocument::JsonFormat  format = QJsonDocument::Compact 
) const

Serializers a generic c++ type to a byte array.

Template Parameters
TThe type of the data to be serialized
Parameters
dataThe data to be serialized
formatThe formatting for the generated json (compact or intended)
Returns
The serialized data as byte array
Exceptions
SerializationExceptionThrown if the serialization fails
See also
JsonSerializer::deserializeFrom, JsonSerializer::serialize

Definition at line 117 of file jsonserializer.h.

◆ serializeTo() [3/4]

QtJsonSerializer::JsonSerializer::serializeTo ( QIODevice device,
const QVariant data,
QJsonDocument::JsonFormat  format = QJsonDocument::Compact 
) const

Serializers a QVariant value to a device.

Parameters
deviceThe device to write the json to
dataThe data to be serialized
formatThe formatting for the generated json (compact or intended)
Exceptions
SerializationExceptionThrown if the serialization fails
See also
JsonSerializer::deserializeFrom, JsonSerializer::serialize

◆ serializeTo() [4/4]

template<typename T >
QtJsonSerializer::JsonSerializer::serializeTo ( QIODevice device,
const T &  data,
QJsonDocument::JsonFormat  format = QJsonDocument::Compact 
) const

Serializers a generic c++ type to a device.

Template Parameters
TThe type of the data to be serialized
Parameters
deviceThe device to write the json to
dataThe data to be serialized
formatThe formatting for the generated json (compact or intended)
Exceptions
SerializationExceptionThrown if the serialization fails
See also
JsonSerializer::deserializeFrom, JsonSerializer::serialize

Definition at line 110 of file jsonserializer.h.

Property Documentation

◆ byteArrayFormat

QtJsonSerializer::JsonSerializer::byteArrayFormat
readwrite

Specifies the format, in which bytearray should be converter to a JSON string.

Default: JsonSerializer::ByteArrayFormat::Base64

When de/serializing QByteArray data, it has to be converted to a string, as json does not support binary data. This property controls the encoding for the serialization and deserialization of such data. Check the enum for the different formats.

Accessors
READbyteArrayFormat()
WRITEsetByteArrayFormat()
NOTIFYbyteArrayFormatChanged()
See also
JsonSerializer::validateBase64, JsonSerializer::ByteArrayFormat

Definition at line 20 of file jsonserializer.h.

◆ validateBase64

QtJsonSerializer::JsonSerializer::validateBase64
readwrite

Specify whether deserializing a QByteArray should verify the data as base64 instead of silent discarding.

Default: true

Applies to deserialization only.
If active, the date is checked first to verify it is actually a base64 encoded string. If thats not the case an exception will be thrown. When disabled, invalid characters are silently discarded, so no error is reported

Accessors
READvalidateBase64()
WRITEsetValidateBase64()
NOTIFYvalidateBase64Changed()
See also
JsonSerializer::byteArrayFormat

Definition at line 22 of file jsonserializer.h.


The documentation for this class was generated from the following files: