Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Working With Jil Serializer And Deserializer Library In C#
WhatsApp
Debendra Dash
8y
51.2k
0
5
100
Article
JIL is one of the fastest Serializer and Deserializer libraries. It is also open source. Jil is an open source library, written by Kevin Montrose and the stack exchange team. It is built on Sigil -- with a number of crazy optimization tricks.To work with JIL Library, you can download it from NuGet Package Manager. Here, I will explain how to Serialize and Deserialize an object, using JIL Library. If we compare JIL with other Serializers and Deserializers available, we can get that JIL is very fast among them.This is the comparison table of JIL with other Serializers and Deserializers.
Now, I will show you the simple speed tester graph for JIL.
Now I will create a simple console application which shows how to work with JIL.
Create a simple console application and add JIL library from Nuget Package as follows.
Now write the following code for Serializing and Deserializing the data as follows.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Diagnostics;
using
Newtonsoft.Json;
using
System.IO;
using
Jil;
namespace
Serialization
{
public
class
Employee
{
public
int
id { get; set; }
public
string Name { get; set; }
public
string Email { get; set; }
public
string Dept { get; set; }
}
class
Program
{
static
void
Main(string[] args)
{
List<Employee> liemp =
new
List<Employee>();
Employee emp =
new
Employee();
liemp.Add(
new
Employee { id = 2, Name =
"Debendra"
, Email =
"
[email protected]
"
, Dept =
"IT"
});
liemp.Add(
new
Employee { id = 3, Name =
"Manoj"
, Email =
"
[email protected]
"
, Dept =
"Sales"
});
liemp.Add(
new
Employee { id = 6, Name =
"Kumar"
, Email =
"
[email protected]
"
, Dept =
"IT"
});
string jsonData1 = SerializeEmployee(liemp);
Console.WriteLine(jsonData1);
Console.WriteLine(
"............JIL Deserialization........"
);
var employeeDeserialized = DeserializeEmployee(jsonData1);
foreach (var data in employeeDeserialized)
{
Console.WriteLine(
"Id="
+ data.id);
Console.WriteLine(
"Name="
+ data.Name);
Console.WriteLine(
"Id="
+ data.Email);
Console.WriteLine(
"Id="
+ data.Dept);
}
Console.ReadLine();
}
private
static
string SerializeEmployee(List<Employee> liemployee)
{
using
(var output =
new
StringWriter())
{
JSON.Serialize(
liemployee,
output
);
return
output.ToString();
}
}
private
static
List<Employee> DeserializeEmployee(string liemployee)
{
List<Employee> li =
new
List<Employee>();
li = JSON.Deserialize<List<Employee>>(liemployee);
return
li;
}
}
}
Now if you run the application you will get the following output.
Thus in this way we can use JIL library to serialize and deserialize the data.
C#
Deserializer Library
Jil Serializer
Up Next
Ebook Download
View all
Mastering SOLID Principles in C#
Read by 2.7k people
Download Now!
Learn
View all
Membership not found