Saturday, May 18, 2013

Ways of object serialization using C#

       Here i discuss how to serialize object state to a file in different formats, showing you 5 different serialization formats plus how to read object from config file:
  • Binary
  • XML
  • JSON
  • Base64
  • DataContract
  • Object in config file
I took a simple 'Person' class to be used for serializations and 'ConfigPerson' class for object read from config file. I used 'ConfigPerson' class for config read, since 'Person' class cant be used for config specific implementation.

For serialization process i created a component called 'Serializer' with below classes. 
'ObjectSerialize' class contains the nested classes for each serialization format and access methods for these classes. Each nested class inherits from abstract base class 'BaseFileChecker' (for logic reuse: file create & open) and implements 'IFormat' interface (for methods decouple: serialize & deserialize).
Check each nested class for format specific code.

For Testing this component i created a console application.
Pressing 1 shows the below result which is showing 'ConfigPerson' object read from app.config file.
Pressing any other key, prompts for serialization formats (applied on 'Person' class) 

When completed all 5 formats, you will see below files in your folder (folder name hardcoded in console project, change it for your requirement).

 Share your thoughts, alternative solutions and other serialization formats in below comments.


Download the project solution as Zip file.


  1. Thanks for the efforts on gathering useful content and sharing here. You can find more questions and answers related to web technologies in the below forum.

    Web technologies question and answers forum

  2. Thanks for sharing very important post with us.the objective in tha blog about web technologies was really nice thanks for sharing this blog.

    web technologies

  3. Quite Interesting post!!! Thanks for posting such a useful post. I wish to read your upcoming post to enhance my skill set, keep blogging.

    Hadoop Training in Chennai|Hadoop Training Chennai

  4. Such as very good information promoting content are provided and more skills are improved after refer that post.To get more details please check our website.
    Oracle Fusion HCM Training in Hyderabad

  5. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

  6. Such a nice blog, I really like what you write in this blog, I also have some relevant Information about if you want more information.

    Workday HCM Online Training

  7. Thank you for sharing such a nice and really very helpful article

    Workday Online Training