Safir SDK Core
Loading...
Searching...
No Matches
Safir::Dob::Typesystem::Serialization Class Reference

Functions for serializing objects to binary, XML and JSON forms. More...

#include <Safir/Dob/Typesystem/Serialization.h>

Static Public Member Functions

static const std::wstring ToXml (const Dob::Typesystem::ObjectConstPtr &object)
 Serialize an object to XML.
 
static const std::wstring ToJson (const Dob::Typesystem::ObjectConstPtr &object)
 Serialize an object to JSON.
 
static Dob::Typesystem::ObjectPtr ToObject (const std::wstring &xml)
 Deserialize an XML serialization.
 
static Dob::Typesystem::ObjectPtr ToObjectFromJson (const std::wstring &json)
 Deserialize an JSON serialization.
 
static const std::wstring ToXml (const BinarySerialization &bin)
 Convert a binary serialization to XML.
 
static const std::wstring ToJson (const BinarySerialization &bin)
 Convert a binary serialization to JSON.
 
static const std::wstring ToXml (const char *const blob)
 Convert a blob to XML.
 
static const std::wstring ToJson (const char *const blob)
 Convert a blob to JSON.
 
static void ToBinary (const Dob::Typesystem::ObjectConstPtr &object, Dob::Typesystem::BinarySerialization &binary)
 Serialize an object to binary form.
 
static Dob::Typesystem::ObjectPtr ToObject (const Dob::Typesystem::BinarySerialization &binary)
 Deserialize a binary serialization and create an object.
 

Detailed Description

Functions for serializing objects to binary, XML and JSON forms.

Member Function Documentation

◆ ToBinary()

static void Safir::Dob::Typesystem::Serialization::ToBinary ( const Dob::Typesystem::ObjectConstPtr & object,
Dob::Typesystem::BinarySerialization & binary )
static

Serialize an object to binary form.

The serialization is put into a variable of type BinarySerialization, which is of type std::vector<char>. If you need to get hold of a "raw" C-pointer to the data use&binary[0]. See Effective STL Item 16 for more info.

Parameters
[in]object- The object to serialize
[out]binary- The destination of the serialization
Exceptions
IllegalValueException- There is something wrong with the object.

◆ ToJson() [1/3]

static const std::wstring Safir::Dob::Typesystem::Serialization::ToJson ( const BinarySerialization & bin)
static

Convert a binary serialization to JSON.

Parameters
[in]bin- the binary serialization to convert to json.
Returns
The json of the binary serialization.

◆ ToJson() [2/3]

static const std::wstring Safir::Dob::Typesystem::Serialization::ToJson ( const char *const blob)
static

Convert a blob to JSON.

Parameters
[in]blob- the blob to convert to json.
Returns
The json of the blob.

◆ ToJson() [3/3]

static const std::wstring Safir::Dob::Typesystem::Serialization::ToJson ( const Dob::Typesystem::ObjectConstPtr & object)
static

Serialize an object to JSON.

Parameters
[in]object- The object to serialize
Returns
The json serialization
Exceptions
IllegalValueException- There is something wrong with the object.

◆ ToObject() [1/2]

static Dob::Typesystem::ObjectPtr Safir::Dob::Typesystem::Serialization::ToObject ( const Dob::Typesystem::BinarySerialization & binary)
static

Deserialize a binary serialization and create an object.

It uses the ObjectFactory to accomplish this. If you have a char * that you want to deserialize the easiest way is to pass it to the ObjectFactory instead.

Parameters
[in]binary- The binary serialization to deserialize.
Returns
A std::shared_ptr to the new object
Exceptions
IllegalValueExceptionIf the type represented by the serialization isn't found in the ObjectFactory.

◆ ToObject() [2/2]

static Dob::Typesystem::ObjectPtr Safir::Dob::Typesystem::Serialization::ToObject ( const std::wstring & xml)
static

Deserialize an XML serialization.

This method creates a new object from a given xml serialization. It uses the ObjectFactory to accomplish this.

Parameters
[in]xml- The xml to convert.
Returns
A std::shared_ptr to the new object
Exceptions
IllegalValueExceptionIf there is something wrong with the XML or if the type represented by the serialization isn't found in the ObjectFactory.

◆ ToObjectFromJson()

static Dob::Typesystem::ObjectPtr Safir::Dob::Typesystem::Serialization::ToObjectFromJson ( const std::wstring & json)
static

Deserialize an JSON serialization.

This method creates a new object from a given json serialization. It uses the ObjectFactory to accomplish this.

Parameters
[in]json- The json to convert.
Returns
A std::shared_ptr to the new object
Exceptions
IllegalValueExceptionIf there is something wrong with the JSON or if the type represented by the serialization isn't found in the ObjectFactory.

◆ ToXml() [1/3]

static const std::wstring Safir::Dob::Typesystem::Serialization::ToXml ( const BinarySerialization & bin)
static

Convert a binary serialization to XML.

Parameters
[in]bin- the binary serialization to convert to xml.
Returns
The xml of the binary serialization.

◆ ToXml() [2/3]

static const std::wstring Safir::Dob::Typesystem::Serialization::ToXml ( const char *const blob)
static

Convert a blob to XML.

Parameters
[in]blob- the blob to convert to xml.
Returns
The xml of the blob.

◆ ToXml() [3/3]

static const std::wstring Safir::Dob::Typesystem::Serialization::ToXml ( const Dob::Typesystem::ObjectConstPtr & object)
static

Serialize an object to XML.

Parameters
[in]object- The object to serialize
Returns
The xml serialization
Exceptions
IllegalValueException- There is something wrong with the object.