In this post I will explain how to combine the reader and writer in a job and how to run the job. We define a job which will transfer the employee records from one file to another file in batches. <batch:job id=”importEmployees”> <batch:step id=”readWriteEmployees”> <batch:tasklet> <batch:chunk reader=”reader” writer=”writer” commit-interval=”50″/> </batch:tasklet> </batch:step> </batch:job> <bean id=”transactionManager” class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”>…… Continue reading Spring Batch Simple Example Part 3
Spring Batch Simple Example Part 2
In this post, I will explain how to write the employee objects created in the reading process to a file. To write the list of employee records in batches, we need to create an instance of org.springframework.batch.item.file.FlatFileItemWriter. It takes two information1) the resource file where the information has to be written2) An instance of LineAggregator…… Continue reading Spring Batch Simple Example Part 2
Spring Batch Simple Example Part 1
In this post and next post, I will introduce Spring Batch to you with a simple example. Spring batch is an open source framework useful for exporting data from source to destination in batches. The framework is very useful for batch applications. Reading data In our example, we will read employee records and move them…… Continue reading Spring Batch Simple Example Part 1
Creating filters in JAX-RS
This post explains how to create filters in JAX-RS code. The filters can be placed before and after the web resource. So we can use the filters for 1) modifying the request 2) restricting certain requests from reaching the webresource 3) modifying the response In the below code I have created a custom filter, which…… Continue reading Creating filters in JAX-RS
BeanParam annotation example
This post will explain the use of BeanParam annotation in JAX-RS with an example. The purpose of BeanParam annotation is to consolidate all the user input (i.e., input through QueryParam, HeaderParam, FormParam, etc) and inject into a given class instance variables. Below is an example of webresource whose only method “retrieveRecord1” has a parameter annotated…… Continue reading BeanParam annotation example
Mapping exceptions to Response in JAX-RS
In JAX-RS, we can map exceptions to a Response. This will be useful in hiding the exceptions from the client of JAX-RS web services. Below is an example showing how to map exceptions to appropriate responses. First we need to implement ExceptionMapper interface as shown below. Here we want to map NullPointer exception to Internal…… Continue reading Mapping exceptions to Response in JAX-RS
Configuring the Jsonb instance
From the previous posts we can see that an instance of Jsonb is used for serialization/deserialization of java objects to/from json format. We can configure the Jsonb instance by creating an instance of JsonbConfig. By default jsonb implementation provider must support the following properties to be configured. jsonb.to.json.formatted – java.lang.Boolean Controls whether or not the…… Continue reading Configuring the Jsonb instance
Serialization of null values when converting from java object to json format
In this post I will explain how serialization of null values feature can be turned on or off. Below is the class structure of the object to be serialized Student 1 import javax.json.bind.annotation.JsonbProperty; 2 3 public class Student { 4 private int id; 5 private String name; 6 private Integer rollnum; 7 8 public int…… Continue reading Serialization of null values when converting from java object to json format
Preventing an property from being serialized to json
By default when an object is serialized to json format, all the properties in the object are serialized. We can prevent this default behavior, by annotating the property with @JsonbTransient annotation. Below is the example. The class to be serialized is Employee Employee 1 import javax.json.bind.annotation.JsonbTransient; 2 3 public class Employee { 4 private int…… Continue reading Preventing an property from being serialized to json
Deserialization of java objects present in JSON format from a file
This post will explain how to read the serialized (JSON) form of Java objects from a file. Person public class Person { private String fName; private String lName; private int age; public String getfName() { return fName; } public void setfName(String fName) { this.fName = fName; } public String getlName() { return lName; } public…… Continue reading Deserialization of java objects present in JSON format from a file