Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
QxJson::Converter< T > Struct Template Reference

The Converter template struct acts as an interface that carries details on how to parse/serialize JSON to various types. More...

Detailed Description

template<typename T>
struct QxJson::Converter< T >

JSON data can be converted to/from an object of any type for which a Converter specialization exists that contains corresponding fromJson() and toJson functions.

By default, conversions are provided for:

Support for additional, non-structural types can be added like so:

class MyType
{
...
};
namespace QxJson
{
template<>
struct Converter<MyType>
{
static Qx::JsonError fromJson(MyType& value, const QJsonValue& jValue)
{
// Assign `value` to complete the conversion
value = //...
// Return an invalid JsonError upon success, or a valid one if an error occurs
return Qx::JsonError();
}
static QJsonObject toJson(const MyType& value)
{
// Use value to return a valid JSON type (i.e. qjson_type concept)
return objFromMyType(value);
}
};
}

If a structural type needs to be registered, the QX_JSON_STRUCT and QX_JSON_MEMBER macros should be used instead.

See also
qx-json.h and keygen().

The documentation for this struct was generated from the following file: