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::CborSerializer Class Reference

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

#include <cborserializer.h>

+ Inheritance diagram for QtJsonSerializer::CborSerializer:

Public Types

enum  ExtendedTags : std::underlying_type_t< QCborTag > {
  GenericObject = 27, RationaleNumber = 30, Identifier = 39, Homogeneous = 41,
  Set = 258, ExplicitMap = 259, NetworkAddress = 260, NetworkAddressPrefix = 261
}
 Additional official CBOR-Tags, taken from https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml. More...
 
enum  CustomTags : std::underlying_type_t< QCborTag > {
  Color = 10000, Font = 10001, Enum = 10002, Flags = 10003,
  ConstructedObject = 10004, Pair = 10005, MultiMap = 10006, VersionNumber = 10007,
  Tuple = 10008, BitArray = 10009, Date = 10010, Time = 10011,
  LocaleISO = 10100, LocaleBCP47 = 10101, GeomSize = 10110, GeomPoint = 10111,
  GeomLine = 10112, GeomRect = 10113, ChronoNanoSeconds = 10120, ChronoMicroSeconds = 10121,
  ChronoMilliSeconds = 10122, ChronoSeconds = 10123, ChronoMinutes = 10124, ChronoHours = 10125
}
 
- 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 setHandleSpecialNumbers (bool handleSpecialNumbers)
 WRITE accessor for CborSerializer::handleSpecialNumbers.
 
- 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 handleSpecialNumbersChanged (bool handleSpecialNumbers, QPrivateSignal)
 NOTIFY accessor for CborSerializer::handleSpecialNumbers.
 
- 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

 CborSerializer (QObject *parent=nullptr)
 Default constructor.
 
bool handleSpecialNumbers () const
 READ accessor for CborSerializer::handleSpecialNumbers.
 
template<typename T >
void setTypeTag (QCborTag tag=static_cast< QCborTag >(NoTag))
 Set a tag to always be used when serializing the given type.
 
void setTypeTag (int metaTypeId, QCborTag tag=static_cast< QCborTag >(NoTag))
 Set a tag to always be used when serializing the given type.
 
template<typename T >
QCborTag typeTag () const
 Returns a tag registered for the given metaTypeId.
 
QCborTag typeTag (int metaTypeId) const override
 Returns a tag registered for the given metaTypeId.
 
QCborValue serialize (const QVariant &data) const
 Serializers a QVariant value to a QCborValue. More...
 
void serializeTo (QIODevice *device, const QVariant &data, QCborValue::EncodingOptions options=QCborValue::NoTransformation) const
 Serializers a QVariant value to a device. More...
 
QByteArray serializeTo (const QVariant &data, QCborValue::EncodingOptions options=QCborValue::NoTransformation) const
 Serializers a QVariant value to a byte array. More...
 
template<typename T >
QCborValue serialize (const T &data) const
 Serializers a c++ type to cbor. More...
 
template<typename T >
void serializeTo (QIODevice *device, const T &data, QCborValue::EncodingOptions options=QCborValue::NoTransformation) const
 Serializers a c++ type to a device. More...
 
template<typename T >
QByteArray serializeTo (const T &data, QCborValue::EncodingOptions options=QCborValue::NoTransformation) const
 Serializers a c++ type to a byte array. More...
 
QVariant deserialize (const QCborValue &cbor, int metaTypeId, QObject *parent=nullptr) const
 Deserializes a QCborValue 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 QCborValue &cbor, QObject *parent=nullptr) const
 Deserializes cbor 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...
 
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.
 
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

bool handleSpecialNumbers
 If enabled, specially tagged number types will be automatically deserialized to their type. 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 CBOR.

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

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

Definition at line 11 of file cborserializer.h.

Member Enumeration Documentation

◆ CustomTags

enum QtJsonSerializer::CborSerializer::CustomTags : std::underlying_type_t< QCborTag >
Enumerator
Color 

Tag used for QColor.

Font 

Tag used for QFont.

Enum 

Tag used for enums.

Flags 

Tag used for flags.

ConstructedObject 

Tag used for constructed object (GenericObject + standard object)

Pair 

Tag used for QPair/std::pair.

MultiMap 

Tag used for QMultiMap/QMultiHash.

VersionNumber 

Tag used for QVersionNumber.

Tuple 

Tag used for std::tuple.

BitArray 

Tag used for QBitArray.

Date 

Tag used for QDate (short ISO format)

Time 

Tag used for QTime (short ISO format)

LocaleISO 

Tag used for QLocale, encoded via the ISO format.

LocaleBCP47 

Tag used for QLocale, encoded via the BCP47 format.

GeomSize 

Tag used for QSize/QSizeF.

GeomPoint 

Tag used for QPoint/QPointF.

GeomLine 

Tag used for QLine/QLineF.

GeomRect 

Tag used for QRect/QRectF.

ChronoNanoSeconds 

Tag used for std::chrono::nanoseconds.

ChronoMicroSeconds 

Tag used for std::chrono::microseconds.

ChronoMilliSeconds 

Tag used for std::chrono::milliseconds.

ChronoSeconds 

Tag used for std::chrono::seconds.

ChronoMinutes 

Tag used for std::chrono::minutes.

ChronoHours 

Tag used for std::chrono::hours.

Definition at line 33 of file cborserializer.h.

◆ ExtendedTags

enum QtJsonSerializer::CborSerializer::ExtendedTags : std::underlying_type_t< QCborTag >

Additional official CBOR-Tags, taken from https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml.

Enumerator
GenericObject 

Serialised language-independent object with type name and constructor arguments.

RationaleNumber 

Rational number.

Identifier 

Identifier.

Homogeneous 

Homogeneous Array.

Set 

Mathematical finite set.

ExplicitMap 

Map datatype with key-value operations (e.g. .get()/.set()/.delete())

NetworkAddress 

Network Address (IPv4 or IPv6 or MAC Address)

NetworkAddressPrefix 

Network Address Prefix (IPv4 or IPv6 Address + Mask Length)

Definition at line 20 of file cborserializer.h.

Member Function Documentation

◆ deserialize() [1/2]

QtJsonSerializer::CborSerializer::deserialize ( const QCborValue cbor,
int  metaTypeId,
QObject parent = nullptr 
) const

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

Parameters
cborThe 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
CborSerializer::serialize, CborSerializer::deserializeFrom

◆ deserialize() [2/2]

template<typename T >
QtJsonSerializer::CborSerializer::deserialize ( const QCborValue cbor,
QObject parent = nullptr 
) const

Deserializes cbor to the given c++ type.

Template Parameters
TThe type of the data to be deserialized
Parameters
cborThe 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
CborSerializer::serialize, CborSerializer::deserializeFrom

Definition at line 172 of file cborserializer.h.

◆ deserializeFrom() [1/4]

QtJsonSerializer::CborSerializer::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
CborSerializer::serializeTo, CborSerializer::deserialize

◆ deserializeFrom() [2/4]

template<typename T >
QtJsonSerializer::CborSerializer::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
CborSerializer::serializeTo, CborSerializer::deserialize

Definition at line 186 of file cborserializer.h.

◆ deserializeFrom() [3/4]

QtJsonSerializer::CborSerializer::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
CborSerializer::serializeTo, CborSerializer::deserialize

◆ deserializeFrom() [4/4]

template<typename T >
QtJsonSerializer::CborSerializer::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
CborSerializer::serializeTo, CborSerializer::deserialize

Definition at line 179 of file cborserializer.h.

◆ deserializeGeneric()

QVariant QtJsonSerializer::CborSerializer::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::CborSerializer::serialize ( const QVariant data) const

Serializers a QVariant value to a QCborValue.

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

◆ serialize() [2/2]

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

Serializers a c++ type to cbor.

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
CborSerializer::deserialize, CborSerializer::serializeTo

Definition at line 151 of file cborserializer.h.

◆ serializeGeneric()

std::variant<QCborValue, QJsonValue> QtJsonSerializer::CborSerializer::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::CborSerializer::serializeTo ( const QVariant data,
QCborValue::EncodingOptions  options = QCborValue::NoTransformation 
) const

Serializers a QVariant value to a byte array.

Parameters
dataThe data to be serialized
optionsThe encoding options for the generated cbor
Returns
The serialized data as byte array
Exceptions
SerializationExceptionThrown if the serialization fails
See also
CborSerializer::deserializeFrom, CborSerializer::serialize

◆ serializeTo() [2/4]

template<typename T >
QtJsonSerializer::CborSerializer::serializeTo ( const T &  data,
QCborValue::EncodingOptions  options = QCborValue::NoTransformation 
) const

Serializers a c++ type to a byte array.

Template Parameters
TThe type of the data to be serialized
Parameters
dataThe data to be serialized
optionsThe encoding options for the generated cbor
Returns
The serialized data as byte array
Exceptions
SerializationExceptionThrown if the serialization fails
See also
CborSerializer::deserializeFrom, CborSerializer::serialize

Definition at line 165 of file cborserializer.h.

◆ serializeTo() [3/4]

QtJsonSerializer::CborSerializer::serializeTo ( QIODevice device,
const QVariant data,
QCborValue::EncodingOptions  options = QCborValue::NoTransformation 
) const

Serializers a QVariant value to a device.

Parameters
deviceThe device to write the json to
dataThe data to be serialized
optionsThe encoding options for the generated cbor
Exceptions
SerializationExceptionThrown if the serialization fails
See also
CborSerializer::deserializeFrom, CborSerializer::serialize

◆ serializeTo() [4/4]

template<typename T >
QtJsonSerializer::CborSerializer::serializeTo ( QIODevice device,
const T &  data,
QCborValue::EncodingOptions  options = QCborValue::NoTransformation 
) const

Serializers a 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
optionsThe encoding options for the generated cbor
Exceptions
SerializationExceptionThrown if the serialization fails
See also
CborSerializer::deserializeFrom, CborSerializer::serialize

Definition at line 158 of file cborserializer.h.

Property Documentation

◆ handleSpecialNumbers

QtJsonSerializer::CborSerializer::handleSpecialNumbers
readwrite

If enabled, specially tagged number types will be automatically deserialized to their type.

Default: false

Applies to deserialization only.
The following table shows which tags are understood by the serializer and how they are deserialized. The 'Checked' column indicates, if the data is tested to fit into the type before deserialzing. If that's not the case, data can be lost without notice.

Tag Types Checked
QCborKnownTags::PositiveBignum q[u]int8 - q[u]int64 (depends on data size) yes
QCborKnownTags::NegativeBignum qint8 - qint64 (depends on data size) yes
QCborKnownTags::Decimal qreal no
QCborKnownTags::Bigfloat qreal no
CborSerializer::ExtendedTags::RationaleNumber qreal no
Warning
Please note that those types have been explicitly created to allow encoding of data that does not fit the standard integer or floating point types. The deserialization of this class however will fail for data that does fit into such a type. If you truely need to handle these types with their full capacity, create a custom converter instead of using this property. It is only provided for convenience.
Accessors
READhandleSpecialNumbers()
WRITEsetHandleSpecialNumbers()
NOTIFYhandleSpecialNumbersChanged()

Definition at line 16 of file cborserializer.h.


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