|
Caffa
1.1.0
C++ Application Framework for Embedded Systems with introspection
|
#include <cafJsonSerializer.h>

Public Types | |
| enum | SerializationType { DATA_FULL, DATA_SKELETON, SCHEMA, PATH } |
| using | FieldSelector = std::function< bool(const FieldHandle *)> |
Public Member Functions | |
| JsonSerializer (ObjectFactory *objectFactory=nullptr) | |
| template<DerivesFromObjectHandle ObjectType> | |
| std::shared_ptr< ObjectType > | cloneObject (const ObjectType *object) const |
| JsonSerializer & | setFieldSelector (FieldSelector fieldSelector) |
| JsonSerializer & | setSerializationType (SerializationType type) |
| JsonSerializer & | setSerializeUuids (bool serializeUuids) |
| ObjectFactory * | objectFactory () const |
| FieldSelector | fieldSelector () const |
| SerializationType | serializationType () const |
| bool | serializeUuids () const |
| JsonSerializer & | setClient (bool client) |
| bool | isClient () const |
| std::string | readUUIDFromObjectString (const std::string &string) const |
| void | readObjectFromString (ObjectHandle *object, const std::string &string) const |
| std::string | writeObjectToString (const ObjectHandle *object) const |
| std::shared_ptr< ObjectHandle > | copyBySerialization (const ObjectHandle *object) const |
| std::shared_ptr< ObjectHandle > | copyAndCastBySerialization (const ObjectHandle *object, const std::string &destinationClassKeyword) const |
| std::shared_ptr< ObjectHandle > | createObjectFromString (const std::string &string) const |
| void | readStream (ObjectHandle *object, std::istream &stream) const |
| void | writeStream (const ObjectHandle *object, std::ostream &stream) const |
| void | readObjectFromJson (ObjectHandle *object, const nlohmann::json &jsonObject) const |
| void | writeObjectToJson (const ObjectHandle *object, nlohmann::json &jsonObject) const |
Static Public Member Functions | |
| static std::string | serializationTypeLabel (SerializationType type) |
Protected Attributes | |
| bool | m_client |
| ObjectFactory * | m_objectFactory |
| FieldSelector | m_fieldSelector |
| SerializationType | m_serializationType |
| bool | m_serializeUuids |
Implementation of Serializer for JSON serialization.
| JsonSerializer::JsonSerializer | ( | ObjectFactory * | objectFactory = nullptr | ) |
Constructor
| objectFactory | The factory used when creating new objects. Not relevant when writing. |
|
inline |
Clone the object by serializing to and from text string
| object | The object to copy |
| destinationClassKeyword | The class of the object to create. |
| std::shared_ptr< ObjectHandle > JsonSerializer::copyAndCastBySerialization | ( | const ObjectHandle * | object, |
| const std::string & | destinationClassKeyword | ||
| ) | const |
Copy the object by serializing to text string but cast to a different class keyword. Note, it is still returned as a base class pointer.
| object | The object to copy |
| destinationClassKeyword | The class of the object to create. |
| std::shared_ptr< ObjectHandle > JsonSerializer::copyBySerialization | ( | const ObjectHandle * | object | ) | const |
Copy the object by serializing to text string and reading in again
| object | The object to copy |
| std::shared_ptr< ObjectHandle > JsonSerializer::createObjectFromString | ( | const std::string & | string | ) | const |
Create a new object from a JSON text string
| string | The JSON text string |
| JsonSerializer::FieldSelector JsonSerializer::fieldSelector | ( | ) | const |
Get the field selector
| ObjectFactory * JsonSerializer::objectFactory | ( | ) | const |
Get the object factory
| void JsonSerializer::readObjectFromString | ( | ObjectHandle * | object, |
| const std::string & | string | ||
| ) | const |
Convenience method to read this particular object (with children) from a json string
| object | ObjectHandle to read in to. |
| string | The JSON text string containing the object |
| void JsonSerializer::readStream | ( | ObjectHandle * | object, |
| std::istream & | stream | ||
| ) | const |
Read object from an input stream
| object | Pointer to object to read into |
| stream | The input stream |
| std::string JsonSerializer::readUUIDFromObjectString | ( | const std::string & | string | ) | const |
Convenience method for reading the class keyword and uuid from a json string. This is used to extract the necessary information to find the object in the object hierarchy.
| string | The JSON text string containing the object |
| JsonSerializer::SerializationType JsonSerializer::serializationType | ( | ) | const |
Check which type of serialization we're doing
| bool JsonSerializer::serializeUuids | ( | ) | const |
Check if we're meant to serialize UUIDs. UUIDs are used for dynamic connection to runtime objects, not for writing to file. Only makes a difference when serializing data.
| JsonSerializer & JsonSerializer::setFieldSelector | ( | FieldSelector | fieldSelector | ) |
Set Field Selector Since it returns a reference it can be used like: Serializer(objectFactory).setFieldSelector(functor);
| fieldSelector |
| JsonSerializer & JsonSerializer::setSerializationType | ( | SerializationType | type | ) |
Set what to serialize (data, schema, etc) Since it returns a reference it can be used like: Serializer(objectFactory).setSerializationTypes(...);
| serializationType |
| JsonSerializer & JsonSerializer::setSerializeUuids | ( | bool | serializeUuids | ) |
Set whether to serialize UUIDs. Only makes a difference when serializing data Since it returns a reference, it can be used like: Serializer(objectFactory).setSerializeUuids(false);
| serializeUuids |
| std::string JsonSerializer::writeObjectToString | ( | const ObjectHandle * | object | ) | const |
Write an object to JSON text string
| object | The object handle to write to string. |
| void JsonSerializer::writeStream | ( | const ObjectHandle * | object, |
| std::ostream & | stream | ||
| ) | const |
Write object to output stream
| object | Pointer to object to write |
| stream | The output stream |
1.8.13