A base class for the CBOR/JSON serializers. More...
#include <serializerbase.h>
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, QJsonValue > | serializeGeneric (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 QMetaObject * | metaObject () 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) |
QThread * | thread () 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) |
T | 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 ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Q_DISABLE_COPY (Class) | |
Q_DISABLE_MOVE (Class) | |
Q_DISABLE_COPY_MOVE (Class) | |
T | qobject_cast (QObject *object) |
T | qobject_cast (const QObject *object) |
T | qFindChild (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
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 TypeExtractor > | extractor (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 | |
QObject * | sender () 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 |
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
Definition at line 34 of file serializerbase.h.
|
strong |
Enum to specify how multi maps and sets should be serialized.
Definition at line 82 of file serializerbase.h.
|
strong |
Enum to specify the modes of polymorphism.
Definition at line 74 of file serializerbase.h.
|
strong |
Flags to specify how strict the serializer should validate when deserializing.
Definition at line 61 of file serializerbase.h.
QtJsonSerializer::SerializerBase::addJsonTypeConverter | ( | ) |
Adds a custom type converter to this serializer.
T | The converter-class to add |
Adds a custom converter class to add additional serialization capabilities. Check the QJsonTypeConverter documentation for details.
Definition at line 330 of file serializerbase.h.
QtJsonSerializer::SerializerBase::addJsonTypeConverter | ( | const QSharedPointer< TypeConverter > & | converter | ) |
Adds a custom type converter to this serializer.
converter | The converter to add |
Adds a custom converter class to add additional serialization capabilities. Check the QJsonTypeConverter documentation for details.
|
static |
Globally registers a converter factory to provide converters for all QJsonSerializer instances.
T | The converter-class to add |
Priority | The priority all the created converters should have |
Creates an instance of a QJsonTypeConverterStandardFactory for the given converter type and registeres it.
Definition at line 323 of file serializerbase.h.
|
static |
Globally registers a converter factory to provide converters for all QJsonSerializer instances.
factory | The factory to add |
Adds a custom converter factory class that can provide a certain converter for all serializer instances globally.
|
pure virtual |
Deserializes CBOR or JSON, depending on the actual instance, to variant.
value | The CBOR/JSON data to be deserialized |
metaTypeId | The target type of the deserialization |
parent | The parent object of the result. Only used if the returend value is a QObject* |
DeserializationException | Thrown if the deserialization fails |
Implemented in QtJsonSerializer::CborSerializer, and QtJsonSerializer::JsonSerializer.
|
inlinestatic |
Registers a custom type for list, set map and optional converisons. Also include pointer converters, if applicable.
T | The 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:
SerializerBase::registerListConverters<T>()
SerializerBase::registerSetConverters<T>()
SerializerBase::registerMapConverters<QString, T>()
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>:
SerializerBase::registerBasicConverters<T*>()
SerializerBase::registerPointerConverters<T>()
SerializerBase::registerBasicConverters<QSharedPointer<T>>()
SerializerBase::registerBasicConverters<QPointer<T>>()
Definition at line 283 of file serializerbase.h.
|
static |
Registers a custom extractor for the given type.
TType | The type to register the extractor for |
TExtractor | The extractor class to be registered |
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.
Definition at line 240 of file serializerbase.h.
|
static |
Registers a custom extractor for the given type.
metaTypeId | The type id to register the extractor for |
extractor | The extractor instance to be registered |
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.
|
inlinestatic |
Registers a custom type for list converisons.
T | The 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:
MetaWriters::SequentialWriter::registerWriter<QList, T>()
MetaWriters::SequentialWriter::registerWriter<QLinkedList, T>()
MetaWriters::SequentialWriter::registerWriter<QVector, T>()
MetaWriters::SequentialWriter::registerWriter<QStack, T>()
MetaWriters::SequentialWriter::registerWriter<QQueue, T>()
Definition at line 246 of file serializerbase.h.
|
inlinestatic |
Registers a custom type for map converisons.
TKey | The map key type to register converters for |
TValue | The map value type to register converters for |
mapTypes | Statically enables registration for QMap based containers |
hashTypes | Statically 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:
mapTypes
is true (the default):MetaWriters::AssociativeWriter::registerWriter<QMap, TKey, TValue>()
MetaWriters::AssociativeWriter::registerWriter<QMultiMap, TKey, TValue>()
hashTypes
is true (the default):MetaWriters::AssociativeWriter::registerWriter<QHash, TKey, TValue>()
MetaWriters::AssociativeWriter::registerWriter<QMultiHash, TKey, TValue>()
Definition at line 262 of file serializerbase.h.
|
inlinestatic |
Registers a custom type for std::optional converisons.
T | The 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:
SerializerBase::registerExtractor<std::optional<T>, TypeExtractors::OptionalExtractor<T>>()
Definition at line 311 of file serializerbase.h.
|
inlinestatic |
Registers two types for pair conversion.
T1 | The first type to register converters for |
T2 | The 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:
SerializerBase::registerExtractor<QPair<T1, T2>, TypeExtractors::PairExtractor<QPair, T1, T2>>()
SerializerBase::registerExtractor<std::pair<T1, T2>, TypeExtractors::PairExtractor<std::pair, T1, T2>>()
Definition at line 298 of file serializerbase.h.
|
inlinestatic |
Registers a custom type for QSharedPointer and QPointer converisons.
T | The 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:
SerializerBase::registerExtractor<QSharedPointer<T>, TypeExtractors::SmartPointerExtractor<QSharedPointer, T>>()
SerializerBase::registerExtractor<QPointer<T>, TypeExtractors::SmartPointerExtractor<QPointer, T>>()
Definition at line 275 of file serializerbase.h.
|
inlinestatic |
Registers a custom type for set converisons.
T | The 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:
Definition at line 256 of file serializerbase.h.
|
inlinestatic |
Registers a number of types for std::tuple conversion.
TArgs | The 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:
SerializerBase::registerExtractor<std::tuple<TArgs...>, TypeExtractors::TupleExtractor<TArgs...>>()
Definition at line 305 of file serializerbase.h.
|
inlinestatic |
Registers a custom type for std::variant converisons.
TArgs | The 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:
SerializerBase::registerExtractor<std::variant<TArgs...>, TypeExtractors::VariantExtractor<TArgs...>>()
Definition at line 317 of file serializerbase.h.
|
pure virtual |
Serializes a given variant to either CBOR or JSON, depending on the actual instance.
value | The data to be serialized |
SerializationException | Thrown if the serialization fails |
Implemented in QtJsonSerializer::CborSerializer, and QtJsonSerializer::JsonSerializer.
|
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.
Accessors | |
---|---|
READ | allowDefaultNull() |
WRITE | setAllowDefaultNull() |
NOTIFY | allowDefaultNullChanged() |
Definition at line 39 of file serializerbase.h.
|
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.
Accessors | |
---|---|
READ | dateAsTimeStamp() |
WRITE | setDateAsTimeStamp() |
NOTIFY | dateAsTimeStampChanged() |
Definition at line 47 of file serializerbase.h.
|
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.
Accessors | |
---|---|
READ | enumAsString() |
WRITE | setEnumAsString() |
NOTIFY | enumAsStringChanged() |
Definition at line 43 of file serializerbase.h.
|
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
objectName
is contained in json, a deserialization will use that value, independent of this property.Accessors | |
---|---|
READ | keepObjectName() |
WRITE | setKeepObjectName() |
NOTIFY | keepObjectNameChanged() |
Definition at line 41 of file serializerbase.h.
|
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:
When in map mode, the following json is generated:
When in list mode, the following is generated instead:
When in dense map mode, the following json is generated:
For deserialization, both formats are always supported.
Accessors | |
---|---|
READ | multiMapMode() |
WRITE | setMultiMapMode() |
NOTIFY | multiMapModeChanged() |
Definition at line 55 of file serializerbase.h.
|
readwrite |
Specifies how the serializer should treat polymorphism for QObject classes.
Default: SerializerBase::Polymorphing::Enabled
Depending on the set mode QObject deriving classes are de/serialized differently. Polymorphing in this context can be easily described with a simple example:
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.
Accessors | |
---|---|
READ | polymorphing() |
WRITE | setPolymorphing() |
NOTIFY | polymorphingChanged() |
Definition at line 53 of file serializerbase.h.
|
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 | |
---|---|
READ | useBcp47Locale() |
WRITE | setUseBcp47Locale() |
NOTIFY | useBcp47LocaleChanged() |
Definition at line 49 of file serializerbase.h.
|
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 | |
---|---|
READ | validationFlags() |
WRITE | setValidationFlags() |
NOTIFY | validationFlagsChanged() |
Definition at line 51 of file serializerbase.h.
|
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.
Accessors | |
---|---|
READ | versionAsString() |
WRITE | setVersionAsString() |
NOTIFY | versionAsStringChanged() |
Definition at line 45 of file serializerbase.h.