Creating a custom serializer or deserializer

In this post under GSon, I will explain with example how to create custom serializer and deserializer and configure Gson object to use it. For our example lets take the below JavaBean Class structure. Student package defaultPackage;import java.util.Date;public class Student { private int id; private String name; private Integer rollnum; private Date date; public int…… Continue reading Creating a custom serializer or deserializer

Serialize and DeSerialize Generic classes

In this post under Gson, I will show with example how to serialize and deserialize generic classes. Below is the complete code for your reference Main class 1 package defaultPackage;2 3 import com.google.gson.Gson;4 import com.google.gson.reflect.TypeToken;5 6 import java.lang.reflect.Type;7 import java.util.ArrayList;8 import java.util.List;9 10 public class GsonDemo16 {11 public static void main(String[] args) {12 List<String> actors…… Continue reading Serialize and DeSerialize Generic classes

Deserializing JSON to Java Object

In this post under Gson. I will show how to deserialize a JSON data back to Java object using Gson framework. For our example I will use the below json data. The json data contains employee information. employee.json {“id”:1,”name”:”employee1″,”ssn”:1234} The class structure of Employee is as shown below Employee class public class Employee { private…… Continue reading Deserializing JSON to Java Object

Serializing Java objects to JSON

In this post under Gson. I will show how to serialize a java object to JSON using Gson framework. Below is the complete code. Main Code 1 import java.io.File; 2 import java.io.FileWriter; 3 import java.io.IOException; 4 5 import com.google.gson.Gson; 6 7 public class GsonDemo1 { 8 public static void main(String[] args) { 9 Employee employee…… Continue reading Serializing Java objects to JSON