Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
Public Member Functions | List of all members
caffa::JsonSerializer Class Reference

#include <cafJsonSerializer.h>

Inheritance diagram for caffa::JsonSerializer:
Inheritance graph
[legend]
Collaboration diagram for caffa::JsonSerializer:
Collaboration graph
[legend]

Public Member Functions

 JsonSerializer (ObjectFactory *objectFactory=nullptr)
 
std::string readUUIDFromObjectString (const std::string &string) const override
 
void readObjectFromString (ObjectHandle *object, const std::string &string) const override
 
std::string writeObjectToString (const ObjectHandle *object) const override
 
std::shared_ptr< ObjectHandlecopyBySerialization (const ObjectHandle *object) const override
 
std::shared_ptr< ObjectHandlecopyAndCastBySerialization (const ObjectHandle *object, const std::string &destinationClassKeyword) const override
 
std::shared_ptr< ObjectHandlecreateObjectFromString (const std::string &string) const override
 
void readStream (ObjectHandle *object, std::istream &stream) const override
 
void writeStream (const ObjectHandle *object, std::ostream &stream) const override
 
void readObjectFromJson (ObjectHandle *object, const nlohmann::json &jsonObject) const
 
void writeObjectToJson (const ObjectHandle *object, nlohmann::json &jsonObject) const
 
- Public Member Functions inherited from caffa::Serializer
 Serializer (ObjectFactory *objectFactory)
 
SerializersetFieldSelector (FieldSelector fieldSelector)
 
SerializersetSerializationType (SerializationType type)
 
SerializersetSerializeUuids (bool serializeUuids)
 
ObjectFactoryobjectFactory () const
 
FieldSelector fieldSelector () const
 
SerializationType serializationType () const
 
bool serializeUuids () const
 

Additional Inherited Members

- Public Types inherited from caffa::Serializer
enum class  SerializationType { DATA_FULL , DATA_SKELETON , SCHEMA }
 
using FieldSelector = std::function< bool(const FieldHandle *)>
 
- Static Public Member Functions inherited from caffa::Serializer
static std::string serializationTypeLabel (SerializationType type)
 
- Protected Attributes inherited from caffa::Serializer
ObjectFactorym_objectFactory
 
FieldSelector m_fieldSelector
 
SerializationType m_serializationType
 
bool m_serializeUuids
 

Detailed Description

Implementation of Serializer for JSON serialization.

Constructor & Destructor Documentation

◆ JsonSerializer()

JsonSerializer::JsonSerializer ( ObjectFactory objectFactory = nullptr)

Constructor

Parameters
objectFactoryThe factory used when creating new objects. Not relevant when writing.

Member Function Documentation

◆ copyAndCastBySerialization()

std::shared_ptr< ObjectHandle > JsonSerializer::copyAndCastBySerialization ( const ObjectHandle object,
const std::string &  destinationClassKeyword 
) const
overridevirtual

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.

Parameters
objectThe object to copy
destinationClassKeywordThe class of the object to create.
Returns
unique ptr containing a new copy

Implements caffa::Serializer.

◆ copyBySerialization()

std::shared_ptr< ObjectHandle > JsonSerializer::copyBySerialization ( const ObjectHandle object) const
overridevirtual

Copy the object by serializing to text string and reading in again

Parameters
objectThe object to copy
Returns
unique ptr containing a new copy

Implements caffa::Serializer.

◆ createObjectFromString()

std::shared_ptr< ObjectHandle > JsonSerializer::createObjectFromString ( const std::string &  string) const
overridevirtual

Create a new object from a JSON text string

Parameters
stringThe JSON text string
Returns
unique ptr to new object

Implements caffa::Serializer.

◆ readObjectFromString()

void JsonSerializer::readObjectFromString ( ObjectHandle object,
const std::string &  string 
) const
overridevirtual

Convenience method to read this particular object (with children) from a json string

Parameters
objectObjectHandle to read in to.
stringThe JSON text string containing the object

Implements caffa::Serializer.

◆ readStream()

void JsonSerializer::readStream ( ObjectHandle object,
std::istream &  stream 
) const
overridevirtual

Read object from an input stream

Parameters
objectPointer to object to read into
streamThe input stream

Implements caffa::Serializer.

◆ readUUIDFromObjectString()

std::string JsonSerializer::readUUIDFromObjectString ( const std::string &  string) const
overridevirtual

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.

Parameters
stringThe JSON text string containing the object
Returns
pair of keyword and uuid in that order.

Implements caffa::Serializer.

◆ writeObjectToString()

std::string JsonSerializer::writeObjectToString ( const ObjectHandle object) const
overridevirtual

Write an object to JSON text string

Parameters
objectThe object handle to write to string.
Returns
A JSON text string

Implements caffa::Serializer.

◆ writeStream()

void JsonSerializer::writeStream ( const ObjectHandle object,
std::ostream &  stream 
) const
overridevirtual

Write object to output stream

Parameters
objectPointer to object to write
streamThe output stream

Implements caffa::Serializer.


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