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

A base class for the CBOR/JSON serializers. More...

#include <serializerbase.h>

+ Inheritance diagram for QtJsonSerializer::SerializerBase:

Public Types

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

virtual std::variant< QCborValue, QJsonValueserializeGeneric (const QVariant &value) const =0
 Serializes a given variant to either CBOR or JSON, depending on the actual instance. More...
 
virtual QVariant deserializeGeneric (const std::variant< QCborValue, QJsonValue > &value, int metaTypeId, QObject *parent=nullptr) const =0
 Deserializes CBOR or JSON, depending on the actual instance, to variant. More...
 
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
 

Static Public Member Functions

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)
 

Protected Member Functions

 SerializerBase (QObject *parent=nullptr)
 Default constructor.
 
virtual QList< int > typesForTag (QCborTag tag) const =0
 
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)
 
- Protected Member Functions inherited from QtJsonSerializer::TypeConverter::SerializationHelper
virtual bool jsonMode () const =0
 Returns true, if de/serializing to JSON, and false for CBOR.
 
virtual QCborTag typeTag (int metaTypeId) const =0
 Returns a tag registered for the given metaTypeId.
 

Properties

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

- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

A base class for the CBOR/JSON serializers.

This class serves as a base class to the JSON and CBOR serializers. It handles all special type and converter registrations and provides most properties that control how data is de/serialized. For more details on how to use the serializers, check the concrete documentations

See also
JsonSerializer, CborSerializer

Definition at line 34 of file serializerbase.h.

Member Enumeration Documentation

◆ MultiMapMode

Enum to specify how multi maps and sets should be serialized.

Enumerator
Map 

Store them as json object, with each element beeing a json array containing the actual values.

List 

Store a list of pairs, where for each pair the first element is the key and the second the value.

DenseMap 

Just like Map, but entries with just one value are stored as that value, instead of an array with one element.

Definition at line 82 of file serializerbase.h.

◆ Polymorphing

Enum to specify the modes of polymorphism.

Enumerator
Disabled 

Do not serialize polymorphic and ignore information about classes in json.

Enabled 

Use polymorphism where declared by the classes/json.

Forced 

Treat every object polymorphic, and required the class information to be present in json.

Definition at line 74 of file serializerbase.h.

◆ ValidationFlag

Flags to specify how strict the serializer should validate when deserializing.

Enumerator
StandardValidation 

Do not perform extra validation, only make sure types are valid and compatible.

NoExtraProperties 

Make sure the json does not contain any properties that are not in the type to deserialize it to.

AllProperties 

Make sure all properties of the type have a value in the deserialized json data.

StrictBasicTypes 

Make shure basic types (string, int, ...) are actually of those types, instead of accepting all that are convertible.

FullPropertyValidation 

Validate properties are exactly the same as declared.

FullValidation 

Validate everything.

Definition at line 61 of file serializerbase.h.

Member Function Documentation

◆ addJsonTypeConverter() [1/2]

template<typename TConverter >
QtJsonSerializer::SerializerBase::addJsonTypeConverter ( )

Adds a custom type converter to this serializer.

Template Parameters
TThe converter-class to add

Adds a custom converter class to add additional serialization capabilities. Check the QJsonTypeConverter documentation for details.

See also
TypeConverter, SerializerBase::addJsonTypeConverterFactory

Definition at line 330 of file serializerbase.h.

◆ addJsonTypeConverter() [2/2]

QtJsonSerializer::SerializerBase::addJsonTypeConverter ( const QSharedPointer< TypeConverter > &  converter)

Adds a custom type converter to this serializer.

Parameters
converterThe converter to add

Adds a custom converter class to add additional serialization capabilities. Check the QJsonTypeConverter documentation for details.

See also
TypeConverter, SerializerBase::addJsonTypeConverterFactory

◆ addJsonTypeConverterFactory() [1/2]

template<typename TConverter , int Priority>
QtJsonSerializer::SerializerBase::addJsonTypeConverterFactory ( )
static

Globally registers a converter factory to provide converters for all QJsonSerializer instances.

Template Parameters
TThe converter-class to add
PriorityThe priority all the created converters should have

Creates an instance of a QJsonTypeConverterStandardFactory for the given converter type and registeres it.

See also
TypeConverterFactory, SerializerBase::addJsonTypeConverter

Definition at line 323 of file serializerbase.h.

◆ addJsonTypeConverterFactory() [2/2]

QtJsonSerializer::SerializerBase::addJsonTypeConverterFactory ( TypeConverterFactory factory)
static

Globally registers a converter factory to provide converters for all QJsonSerializer instances.

Parameters
factoryThe factory to add

Adds a custom converter factory class that can provide a certain converter for all serializer instances globally.

See also
TypeConverterFactory, SerializerBase::addJsonTypeConverterFactory

◆ deserializeGeneric()

QtJsonSerializer::SerializerBase::deserializeGeneric ( const std::variant< QCborValue, QJsonValue > &  value,
int  metaTypeId,
QObject parent = nullptr 
) const
pure virtual

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

Implemented in QtJsonSerializer::CborSerializer, and QtJsonSerializer::JsonSerializer.

◆ registerBasicConverters()

template<typename T >
QtJsonSerializer::SerializerBase::registerBasicConverters ( )
inlinestatic

Registers a custom type for list, set map and optional converisons. Also include pointer converters, if applicable.

Template Parameters
TThe type to register converters for

A shortcut for all the container registrations SerializerBase provides. For any class that does not inherit QObject, the method internally calls:

For a T that extends QObject, it instead calls the following. Please not that you have to register such a type without the pointer-star, e.g. SerializerBase::registerBasicConverters<QFile>:

See also
SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverter, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters, registerTypes()

Definition at line 283 of file serializerbase.h.

◆ registerExtractor() [1/2]

template<typename TType , typename TExtractor >
QtJsonSerializer::SerializerBase::registerExtractor ( )
static

Registers a custom extractor for the given type.

Template Parameters
TTypeThe type to register the extractor for
TExtractorThe extractor class to be registered
Note
This method is only needed when creating custom serializers

Use this method to register custom extractors, as used by some custom converters. You can obtain extractors for a certain type via TypeConverter::SerializationHelper::extractor from within the converter.

Check the TypeExtractor documentation for more details on how to use extractors.

See also
TypeExtractor, TypeConverter::SerializationHelper::extractor

Definition at line 240 of file serializerbase.h.

◆ registerExtractor() [2/2]

QtJsonSerializer::SerializerBase::registerExtractor ( int  metaTypeId,
const QSharedPointer< TypeExtractor > &  extractor 
)
static

Registers a custom extractor for the given type.

Parameters
metaTypeIdThe type id to register the extractor for
extractorThe extractor instance to be registered
Note
This method is only needed when creating custom serializers

Use this method to register custom extractors, as used by some custom converters. You can obtain extractors for a certain type via TypeConverter::SerializationHelper::extractor from within the converter.

Check the TypeExtractor documentation for more details on how to use extractors.

See also
TypeExtractor, TypeConverter::SerializationHelper::extractor

◆ registerListConverters()

template<typename T >
QtJsonSerializer::SerializerBase::registerListConverters ( )
inlinestatic

Registers a custom type for list converisons.

Template Parameters
TThe type to register converters for

Performs the registration of converters for list-like Qt containers. This conversion is a requirement for the serializer, if you want to be able to serialize lists of a type. The function calls the following methods for the given type:

See also
SerializerBase::registerBasicConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverter, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters, registerTypes()

Definition at line 246 of file serializerbase.h.

◆ registerMapConverters()

template<typename TKey , typename TValue , bool mapTypes, bool hashTypes>
QtJsonSerializer::SerializerBase::registerMapConverters ( )
inlinestatic

Registers a custom type for map converisons.

Template Parameters
TKeyThe map key type to register converters for
TValueThe map value type to register converters for
mapTypesStatically enables registration for QMap based containers
hashTypesStatically enables registration for QHash based containers

Performs the registration of converters for map-like Qt containers. This conversion is a requirement for the serializer, if you want to be able to serialize maps of a type. The function calls the following methods for the given type:

See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverter, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters, registerTypes()

Definition at line 262 of file serializerbase.h.

◆ registerOptionalConverters()

template<typename T >
QtJsonSerializer::SerializerBase::registerOptionalConverters ( )
inlinestatic

Registers a custom type for std::optional converisons.

Template Parameters
TThe type that the std::optional wraps

Performs the registration of an extractor for std::optional<T>. This extractor is a requirement for the serializer, if you want to be able to serialize optionals with the given type. The function calls the following methods for the given type:

See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverters, SerializerBase::registerVariantConverters

Definition at line 311 of file serializerbase.h.

◆ registerPairConverters()

template<typename T1 , typename T2 >
QtJsonSerializer::SerializerBase::registerPairConverters ( )
inlinestatic

Registers two types for pair conversion.

Template Parameters
T1The first type to register converters for
T2The second type to register converters for

Performs the registration of an extractor for QPair<T1, T2> and std::pair<T1, T2>. This extractor is a requirement for the serializer, if you want to be able to serialize pairs with the given two types. The function calls the following methods for the given type:

Attention
Only this very specific combination in this specific order is registered. If you change one type to another, or swap the two types, you need to call this method again with this different pair.
See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerTupleConverter, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters

Definition at line 298 of file serializerbase.h.

◆ registerPointerConverters()

template<typename T >
QtJsonSerializer::SerializerBase::registerPointerConverters ( )
inlinestatic

Registers a custom type for QSharedPointer and QPointer converisons.

Template Parameters
TThe type to register converters for

Performs the registration of converters for QSharedPointer<T> <--> T* and QPointer<T> <--> T* (If T is a QObject class). This conversion is a requirement for the serializer, if you want to be able to serialize QSharedPointers or QPointers of a type. The function calls the following methods for the given type:

See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverter, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters, registerTypes()

Definition at line 275 of file serializerbase.h.

◆ registerSetConverters()

template<typename T >
QtJsonSerializer::SerializerBase::registerSetConverters ( )
inlinestatic

Registers a custom type for set converisons.

Template Parameters
TThe type to register converters for

Performs the registration of converters for set-like Qt containers. This conversion is a requirement for the serializer, if you want to be able to serialize sets of a type. The function calls the following methods for the given type:

See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverter, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters, registerTypes()

Definition at line 256 of file serializerbase.h.

◆ registerTupleConverters()

template<typename... TArgs>
QtJsonSerializer::SerializerBase::registerTupleConverters ( )
inlinestatic

Registers a number of types for std::tuple conversion.

Template Parameters
TArgsThe types that make up the tuple to register converters for

Performs the registration of an extractor for std::tuple<TArgs...>. This extractor is a requirement for the serializer, if you want to be able to serialize tuples with the given types. The function calls the following methods for the given type:

Attention
Only this very specific combination in this specific order is registered. If you change one type to another, or swap the types, you need to call this method again with this different type set.
See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerOptionalConverters, SerializerBase::registerVariantConverters

Definition at line 305 of file serializerbase.h.

◆ registerVariantConverters()

template<typename... TArgs>
QtJsonSerializer::SerializerBase::registerVariantConverters ( )
inlinestatic

Registers a custom type for std::variant converisons.

Template Parameters
TArgsThe types that make up the variant to register converters for

Performs the registration of an extractor for std::variant<TArgs...>. This extractor is a requirement for the serializer, if you want to be able to serialize variants with the given types. The function calls the following methods for the given type:

Attention
Only this very specific combination in this specific order is registered. If you change one type to another, you need to call this method again with this different type set.
See also
SerializerBase::registerBasicConverters, SerializerBase::registerListConverters, SerializerBase::registerSetConverters, SerializerBase::registerMapConverters, SerializerBase::registerPointerConverters, SerializerBase::registerPairConverters, SerializerBase::registerTupleConverters, SerializerBase::registerOptionalConverters

Definition at line 317 of file serializerbase.h.

◆ serializeGeneric()

QtJsonSerializer::SerializerBase::serializeGeneric ( const QVariant value) const
pure virtual

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

Implemented in QtJsonSerializer::CborSerializer, and QtJsonSerializer::JsonSerializer.

Property Documentation

◆ allowDefaultNull

QtJsonSerializer::SerializerBase::allowDefaultNull
readwrite

Specifies whether null for value types is allowed or not.

Default: false

Applies to deserialization only.
If set to false, a null json value can only be converted to a QObject (nullptr)! For value types (including Q_GADGETs!), the conversion will fail instead. This is a strict mode, since for value types, there is no null value.
If set to true, null is allowed for all types. If it's not a QObject, a default constructed value will be used.

Note
If you are deserializing json from external sources, it's possible they don't follow this approach, and in order to get a working deserialization, you will have to enable this property.
Accessors
READallowDefaultNull()
WRITEsetAllowDefaultNull()
NOTIFYallowDefaultNullChanged()

Definition at line 39 of file serializerbase.h.

◆ dateAsTimeStamp

QtJsonSerializer::SerializerBase::dateAsTimeStamp
readwrite

Specifies whether datetimes should be serialized as datetime string or as unix timestamp.

Default: false

Applies to serialization only.
By default, QDateTime is serialized as an ISO date string, including milliseconds. If you want to serialize them as an integer representing a unix timestamp (seconds since epoche), enable this propterty.

Note
For deserialization, both strings and timestamps are always correctly deserialized.
Accessors
READdateAsTimeStamp()
WRITEsetDateAsTimeStamp()
NOTIFYdateAsTimeStampChanged()
See also
QDateTime

Definition at line 47 of file serializerbase.h.

◆ enumAsString

QtJsonSerializer::SerializerBase::enumAsString
readwrite

Specifies whether enums should be serialized as integer or as string.

Default: false

Applies to serialization only.
By default, enums and flags are serialized as an integer, representing their value. If you want to serialize them as a string, the "name" of each value, enable this propterty.

Note
For deserialization, both int and string are always correctly deserialized.
Accessors
READenumAsString()
WRITEsetEnumAsString()
NOTIFYenumAsStringChanged()
See also
QMetaEnum

Definition at line 43 of file serializerbase.h.

◆ keepObjectName

QtJsonSerializer::SerializerBase::keepObjectName
readwrite

Specifies whether the objectName property of QObjects should be serialized.

Default: false

Applies to serialization only.
By default, the QObject::objectName property will not be serialized for QObjects! If you need to keep this information, set the property to true

Note
If the objectName is contained in json, a deserialization will use that value, independent of this property.
Accessors
READkeepObjectName()
WRITEsetKeepObjectName()
NOTIFYkeepObjectNameChanged()
See also
QObject::objectName

Definition at line 41 of file serializerbase.h.

◆ multiMapMode

QtJsonSerializer::SerializerBase::multiMapMode
readwrite

Specifies how multi maps and sets should be serialized.

Default: SerializerBase::MultiMapMode::Map

Applies to serialization only.
Selects how QMultiMap and QMultiHash are serialized. There are two options. Assuimg you have the following multi map:

map.insert("a", 1);
map.insert("a", 2);
map.insert("b", 3);

When in map mode, the following json is generated:

{
"a": [1, 2],
"b": [3]
}

When in list mode, the following is generated instead:

[
["a", 1],
["a", 2],
["b", 3],
]

When in dense map mode, the following json is generated:

{
"a": [1, 2],
"b": 3
}

For deserialization, both formats are always supported.

Accessors
READmultiMapMode()
WRITEsetMultiMapMode()
NOTIFYmultiMapModeChanged()
See also
SerializerBase::MultiMapMode

Definition at line 55 of file serializerbase.h.

◆ polymorphing

QtJsonSerializer::SerializerBase::polymorphing
readwrite

Specifies how the serializer should treat polymorphism for QObject classes.

Default: SerializerBase::Polymorphing::Enabled

Attention
Only applicable for QObject deriving classes

Depending on the set mode QObject deriving classes are de/serialized differently. Polymorphing in this context can be easily described with a simple example:

class Foo : public QObject {
//...
Q_PROPERTY(int foo MEMBER foo)
//...
};
class Bar : public Foo {
//...
Q_PROPERTY(int bar MEMBER bar)
Q_CLASSINFO("polymorphic", "true")
//...
};

Assuming you are de/serializing Foo*, but it actually is a Bar* object, for example: serialize<Foo*>(new Bar());

For Serialization:
With polymorphing QJsonSerialzer::Disabled, any additional information about a type is ignored. Bar is serialized as Foo, and the json would only contain the foo property. With it beeing QJsonSerialzer::Enabled, by default no polymorphic information is stored. However, if the type "declares" polymorphism (as in this example Bar does) it is stored. So here Bar is actually serialized as Bar. In order to make deserialization possible, an additional json value, @class is created containing the actual class name, Bar. The json contains this property, the foo and the bar property. If polymorphism is QJsonSerialzer::Forced, any type is treated like Bar in the previous case, even if no polymorphism is specified. For all types, even simple QObjects, the @class is added and the actual typed serialized.

For Deserialization:
With polymorphing QJsonSerialzer::Disabled, the @class json property is ignored, and a value always deserialized as the given property type. So even if @@class is set to Bar, only a Foo object is created, and the bar property ignored. By using QJsonSerialzer::Enabled, if the json does contain the @class property, the serializer creates an instance of the class named by this property. Here, a Bar object is created, with both the foo and the bar property correctly read. When set to QJsonSerialzer::Forced, every json object to be deserialized as QObject must have the @class property, or otherwise an exception is thrown.

Declare objects polymorphic:
There are to ways to make objects polymorphic. The first is static and uses Q_CLASSINFO. Simply add the macro to the class that should be polymorphic as Q_CLASSINFO("polymorphic", "true"). You can also set it to false, to disable polymorphism in case the class you inherit has this already set to true.

The second way is to use a dynamic property. The property overrides the classinfo, but has to be set on an actual instance of the object to be serialized. Set the property by calling setProperty("__qt_json_serializer_polymorphic", true);. Just like with class info, you can set it to false to disable it.

Note
This is only required for serialization. When deserializing, Polymorphism is determined by the @class property. If it is present, the data is treated polymorphic.
Accessors
READpolymorphing()
WRITEsetPolymorphing()
NOTIFYpolymorphingChanged()

Definition at line 53 of file serializerbase.h.

◆ useBcp47Locale

QtJsonSerializer::SerializerBase::useBcp47Locale
readwrite

Specifies whether serializing a QLocale should use the bcp47 format.

Default: true

Applies to serialization only.
The property can be used to change how QLocale is serialized. If active, a bcp47 local string is created (See QLocale::bcp47Name()). That string is able to encode all information contained in the locale, but is not as wide spread as the "simple name format". That one is used if set to false (See QLocale::name())

Both formats are accepted for deserialization

Accessors
READuseBcp47Locale()
WRITEsetUseBcp47Locale()
NOTIFYuseBcp47LocaleChanged()
See also
QLocale::bcp47Name, QLocale::name

Definition at line 49 of file serializerbase.h.

◆ validationFlags

QtJsonSerializer::SerializerBase::validationFlags
readwrite

Specifies how strictly the serializer should verify data when deserializing.

Default: SerializerBase::ValidationFlag::StandardValidation

Applies to deserialization only.
By specifying those flags, you can set which additional attributes the serializer should check when deserializing. In those stricter modes, the serializer will fail with an exception if the conditions are not met instead of simply using defaults values etc.

Accessors
READvalidationFlags()
WRITEsetValidationFlags()
NOTIFYvalidationFlagsChanged()
See also
SerializerBase::ValidationFlag

Definition at line 51 of file serializerbase.h.

◆ versionAsString

QtJsonSerializer::SerializerBase::versionAsString
readwrite

Specifies whether enums should be serialized as array of integers or as string.

Default: false

Applies to serialization only.
By default, QVersionNumber is serialized as an array of integers, representing the different segments. If you want to serialize them as a string, containing the segments seperated by dots, enable this propterty.

Note
For deserialization, both arrays of integers and strings are always correctly deserialized.
Accessors
READversionAsString()
WRITEsetVersionAsString()
NOTIFYversionAsStringChanged()
See also
QVersionNumber

Definition at line 45 of file serializerbase.h.


The documentation for this class was generated from the following files:
QMultiMap
QObject::Q_PROPERTY
Q_PROPERTY(...)
QObject::Q_CLASSINFO
Q_CLASSINFO(Name, Value)
QObject
QtConcurrent::map
QFuture< void > map(Sequence &sequence, MapFunctor function)