IGLib  1.7.2
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Lib.SerializerJson Class Reference

Helper class for JSON serialization and deserialization. This class enables formatting of the generated JSON with propper indentation, which is not the case with its base class. JSON Serializer has several limitations, such as: More...

+ Inheritance diagram for IG.Lib.SerializerJson:
+ Collaboration diagram for IG.Lib.SerializerJson:

Public Member Functions

 SerializerJson ()
 
 SerializerJson (bool formatted)
 
override void Serialize< T > (T serializedObject, Stream serializationStream)
 Serializes the specified object and outputs it to a stream. More...
 
- Public Member Functions inherited from IG.Lib.SerializerJsonBase
 SerializerJsonBase ()
 Creates a JSON serialization class. More...
 
override void Serialize< T > (T serializedObject, Stream serializationStream)
 Serializes the specified object and outputs it to a stream. More...
 
override T Deserialize< T > (Stream deserializationStream)
 Deserializes an object from the specified stream containing JSON representation of the object. Deserialized object is instantiated and returned. More...
 
- Public Member Functions inherited from IG.Lib.SerializerBase
 SerializerBase ()
 
void Serialize< T > (T serializedObject, string filePath)
 Serializes the specified object and outputs it to a file. If the specified file exists then it is overwritten. More...
 
void Serialize< T > (T serializedObject, string filePath, bool append)
 Serializes the specified object and outputs it to a file. More...
 
string Serialize< T > (T obj)
 Serializes the specified object to a string and returns it. More...
 
DeserializeString< T > (string strSerialized)
 Deserializes an object from JSON - serialized string representation and returns it. More...
 
DeserializeFile< T > (string filePath)
 Deserializes an object from JSON - serialized file and returns it. More...
 

Properties

static new SerializerJson Global [get]
 Gets a global helper object for JSON serialization. More...
 
bool Formatted [get, set]
 
JsonFormatter Formatter [get, set]
 
- Properties inherited from IG.Lib.SerializerJsonBase
static SerializerJsonBase Global [get]
 Gets a global helper object for JSON serialization. More...
 

Private Attributes

bool _formatted
 
JsonFormatter _formatter
 

Static Private Attributes

static SerializerJson _global = new SerializerJson()
 

Additional Inherited Members

- Static Public Member Functions inherited from IG.Lib.SerializerBase
static void TestSerializationAll (string outputDirectory)
 Tests different serialization methods with different data. More...
 
static void TestSerializationDto< TypeDto, Type > (ISerializer serializer, Type serializedObject, string filePath, bool firstStep, bool secondStep)
 Test serialization performed by the specified serialization helper class. This test does not perform only serialization/deserialization, but also performs copying of an object to and from the corresponding DTO (Data Transfer Object). It is actually DTO that is serialized and deserialized. This function creates a test object, copies it to the corresponding DTO (Data Transfer object) of the specified type, serializes it and stores it to a file, then deserializes the DTO (instantiates a new object for the stored record), copies the contents of the DTO to a new object, creates a new object and copies data to it from the DTO, and serializes the DTO again and writes it into another file in the same directory, but with a modified name. Both files can then be compared in order to see if something was lost during conversions or serialization/deserialization. More...
 
static void TestSerializationDto< TypeDto, Type, BaseType > (ISerializer serializer, Type serializedObject, string filePath, bool firstStep, bool secondStep)
 Test serialization performed by the specified serialization helper class. This test does not perform only serialization/deserialization, but also performs copying of an object to and from the corresponding DTO (Data Transfer Object). It is actually the DTO that is serialized and deserialized. This function creates a test object, copies it to the corresponding DTO (Data Transfer object) of the specified type, serializes it and stores it to a file, then deserializes the DTO (instantiates a new object for the stored record), copies the contents of the DTO to a new object, creates a new object and copies data to it from the DTO, and serializes the DTO again and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost during conversions or serialization/deserialization. IMPORTANT REMARK: In most cases one will not need this function, but can use the variant with only two type parameters (BaseType omitted). More...
 
static void TestSerialization< SerializationTestClass > (ISerializer serializer, SerializationTestClass serObject, string filePath)
 Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
 
static void TestSerialization< TypeSer > (ISerializer serializer, TypeSer serObject, string filePath, bool firstStep, bool secondStep)
 Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
 
static void TestSerializationJSON (string filePath, object serObject)
 Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
 
static void TestSerializationJSON (string filePath)
 Test serialization performed by the JSon serializer. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
 
static void TestType< T > (T obj)
 Writes the type of the object passed as parameter in two ways: by using tpye parameter of the generic method and by using object's GetType() method. The object itself is not printed out. More...
 
static void TestType< T > (T obj, bool printObject)
 Writes the type of the object passed as parameter in two ways: by using tpye parameter of the generic method and by using object's GetType() method. More...
 
static void ExampleTestType ()
 Testing the type of the object within a generic method. More...
 

Detailed Description

Helper class for JSON serialization and deserialization. This class enables formatting of the generated JSON with propper indentation, which is not the case with its base class. JSON Serializer has several limitations, such as:

  • cyclic references are not supported.
  • rectangular arrays are not supported. Jagged arrays must be used.

$A Igor jun09;

Constructor & Destructor Documentation

IG.Lib.SerializerJson.SerializerJson ( )
inline
IG.Lib.SerializerJson.SerializerJson ( bool  formatted)
inline

Member Function Documentation

override void IG.Lib.SerializerJson.Serialize< T > ( serializedObject,
Stream  serializationStream 
)
inline

Serializes the specified object and outputs it to a stream.

Template Parameters
TType of the object to be serialized.
Parameters
serializedObjectObject to be serialized.
serializationStreamStream on which the serialized object is output.

Implements IG.Lib.ISerializer.

References IG.Lib.JsonFormatter.Format().

Member Data Documentation

SerializerJson IG.Lib.SerializerJson._global = new SerializerJson()
staticprivate
bool IG.Lib.SerializerJson._formatted
private
JsonFormatter IG.Lib.SerializerJson._formatter
private

Property Documentation

new SerializerJson IG.Lib.SerializerJson.Global
staticget

Gets a global helper object for JSON serialization.

bool IG.Lib.SerializerJson.Formatted
getset
JsonFormatter IG.Lib.SerializerJson.Formatter
getset

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