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

Writing JSON Data using JsonWriter

This post explains how to write json data to a file using JsonWriter. With JsonWriter we dont need to build the entire object in memory. The code explains how to write the below json data [ { “id”: 1, “text”: “text1”, “array”: null }, { “id”: 2, “text”: “text2!”, “array”: [ 50.454722, -104.606667 ] }…… Continue reading Writing JSON Data using JsonWriter

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

Chaining multiple JobParametersValidator implementations

In this post under Spring Batch, I will show how to chain multiple JobParametersValidator interface implementations. For our example I will create two JobParametersValidator interface implementations as shown below Validator1 package package23; import java.util.Map; import org.springframework.batch.core.JobParameter; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersInvalidException; import org.springframework.batch.core.JobParametersValidator; public class Validator1 implements JobParametersValidator { @Override public void validate(JobParameters jobParameters) throws JobParametersInvalidException…… Continue reading Chaining multiple JobParametersValidator implementations