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

@SerializedName annotation example

In this post under Gson, I will explain with example the purpose of “@SerializedName” annotation. By default when we serialize an object to Json, the class field names are used as key names in the Json. For example if we have the below class structure JavaBean class structure package defaultPackage;import com.google.gson.annotations.SerializedName;import java.util.List;public class Author {…… Continue reading @SerializedName annotation example

ExclusionStrategy example during deserialization of object

In this post under Gson, I will explain how we can exclude certain fields of a json data from being deserialized with an example. Below is the Employee class structure that will be used to create an instance and its field are set with the values obtained from Employee.json file. Employee class public class Employee…… Continue reading ExclusionStrategy example during deserialization of object

ExclusionStrategy example during serialization of object

In this post under Gson, I will explain how we can exclude certain fields of a class from being serialized with an example. Below is the Employee class structure that we want to serialize Employee public class Employee { private int id; private String name; private int ssn; private boolean terminated; public int getId() {…… Continue reading ExclusionStrategy example during serialization of object

Annotation Since and setVersion method

In this post under Gson, I will explain with an example how to use @Since annotation. The @Since annotation is used in combination with “GsonBuilder.setVersion” method. The annotation has no effect if it is not used along with “GsonBuilder.setVersion” method. The @Since annotation is used for the fields of the class and it accepts a…… Continue reading Annotation Since and setVersion method

Annotation Until and setVersion method

In this post under Gson, I will explain with an example how to use @Until annotation. The @Until annotation is used in combination with “GsonBuilder.setVersion” method. The annotation has no effect if it is not used along with “GsonBuilder.setVersion” method. The @Until annotation is used for the fields of the class and it accepts a…… Continue reading Annotation Until and setVersion method

FieldNamingStrategy Example

In my previous post “FieldNamingPolicy Example”, I explained with an example how to change the naming convention using out of the box provided standard naming conventions. In this post, I will explain with an example how to create your own custom naming conventions and configure the Gson to use it. To create our own custom…… Continue reading FieldNamingStrategy Example