Serializing Java object to YAML format

In this post under YamlBeans, I will show with an example of how to serialize a Java object to YAML format. Below is the complete code Main Code 1 import java.io.File; 2 import java.io.FileWriter; 3 import java.io.IOException; 4 import java.util.ArrayList; 5 import java.util.List; 6 7 import com.esotericsoftware.yamlbeans.YamlWriter; 8 9 public class YamlDemo1 { 10 public…… Continue reading Serializing Java object to YAML format

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

Configuring Gson to serialize objects with fields having null value

Whenever we serialize a java object to JSON using Gson framework, by default fields with null values are ignored. As shown in the below code Main code import com.google.gson.Gson; public class GsonDemo7 { public static void main(String[] args) { Student student = new Student(); student.setId(1); student.setName(“name1”); student.setRollnum(100); student.setDate(null); Gson gson = new Gson(); String result…… Continue reading Configuring Gson to serialize objects with fields having null value