Daily Archives: November 20, 2020

VB.NET || Universal Object Serializer and Deserializer Using VB.NET

The following is a module with functions which demonstrates how to create a simple universal object serializer and deserializer using VB.NET.

The following functions take in a instance of the abstract classesObjectSerializer‘, and ‘ObjectDeserializer‘. Those classes defines the functionality that is common to all the classes derived from it. They are what carries out the actual serialization and deserialization.

Breaking things up like so makes it easy to have different serializations with only calling one function.

Note: The functions in this module uses code from previous articles which explains how to serialize and deserialize objects.

For those examples of how to serialize and deserialize objects using Json and XML, see below:


1. JsonSerializer

The example below demonstrates the use of ‘Utils.Objects.JsonSerializer‘ to serialize an object to Json.

By changing the second parameter, calling the same function will change its behavior.


2. JsonDeserializer

The example below demonstrates the use of ‘Utils.Objects.JsonDeserializer‘ to deserialize an object from Json.

By changing the second parameter, calling the same function will change its behavior.


3. XmlSerializer

The example below demonstrates the use of ‘Utils.Objects.XmlSerializer‘ to serialize an object to Xml.

By changing the second parameter, calling the same function will change its behavior.


4. XmlDeserializer

The example below demonstrates the use of ‘Utils.Objects.XmlDeserializer‘ to deserialize an object from xml.

By changing the second parameter, calling the same function will change its behavior.


5. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


6. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.