Validating Items using ValidatingItemProcessor

In this post under Spring Batch, I will introduce ValidatingItemProcessor and explain how to use it with an example. ValidatingItemProcessor is a implementation of org.springframework.batch.item.ItemProcessor interface. As mentioned in my previous posts, implementation of ItemProcessor is used to place business logic. The implementation of ItemProcessor which contains the business logic is placed between the reader…… Continue reading Validating Items using ValidatingItemProcessor

Advertisements

SuffixRecordSeparatorPolicy example

In this post under Spring Batch, I will explain the purpose and how to use SuffixRecordSeparatorPolicy class with an example. SuffixRecordSeparatorPolicy class is a concrete implementation of org.springframework.batch.item.file.separator.RecordSeparatorPolicy interface. In one of my previous post I have explained the purpose of RecordSeparatorPolicy and how to use it. For recap, RecordSeparatorPolicy interface is used to tell…… Continue reading SuffixRecordSeparatorPolicy example

JsonRecordSeparatorPolicy example

In this post under Spring Batch, I will explain the purpose and how to use JsonRecordSeparatorPolicy class with an example. JsonRecordSeparatorPolicy class is a concrete implementation of org.springframework.batch.item.file.separator.RecordSeparatorPolicy interface. In one of my previous post I have explained the purpose of RecordSeparatorPolicy and how to use it. For recap, RecordSeparatorPolicy interface is used to tell…… Continue reading JsonRecordSeparatorPolicy example

JsonLineMapper Example

In this post under Spring Batch, I will explain the purpose of JsonLineMapper with an example. JsonLineMapper is used with reader bean for reading file containing JSON input as shown below JsonFileInput.txt {“id”:”id0″,”name”:”name0″,”status”:”status0″,”salary”:0} {“id”:”id1″,”name”:”name1″,”status”:”status1″,”salary”:1} {“id”:”id2″,”name”:”name2″,”status”:”status2″,”salary”:2} {“id”:”id3″,”name”:”name3″,”status”:”status3″,”salary”:3} {“id”:”id4″,”name”:”name4″,”status”:”status4″,”salary”:4} {“id”:”id5″,”name”:”name5″,”status”:”status5″,”salary”:5} {“id”:”id6″,”name”:”name6″,”status”:”status6″,”salary”:6} {“id”:”id7″,”name”:”name7″,”status”:”status7″,”salary”:7} {“id”:”id8″,”name”:”name8″,”status”:”status8″,”salary”:8} {“id”:”id9″,”name”:”name9″,”status”:”status9″,”salary”:9} Each line in the file is interpreted as a JSON object by JsonLineMapper.…… Continue reading JsonLineMapper Example

Transforming items using ItemProcessor

In this post under Spring Batch, I will explain how to achieve Item Transformation using ItemProcessor interface. Item Transformation process transforms the items read by reader before sending them to the writer. The transformation involves changing the state of the read item or creating a completely new object. In the second case, the written item…… Continue reading Transforming items using ItemProcessor

Using custom delimiter while reading and writing batch file

In all previous Spring Batch posts, the DelimitedLineAggregator(which creates String format of java objects) and DelimitedLineTokenizer (which extracts fields from each record) assume ‘,’ as delimiter as shown below EMP_ID0,EMP_NAME0,EMP_STATUS0,0 EMP_ID1,EMP_NAME1,EMP_STATUS1,1 EMP_ID2,EMP_NAME2,EMP_STATUS2,2 EMP_ID3,EMP_NAME3,EMP_STATUS3,3 We can use other symbols as delimiter and inform DelimitedLineAggregator and DelimitedLineTokenizer about this. At the time of reading and writing, the…… Continue reading Using custom delimiter while reading and writing batch file

Validating JobParameters using JobParametersValidator interface

In this post under Spring Batch, I will explain how to validate the parameters passed to the job instance. The interface we will be using for validating the Job parameters is org.springframework.batch.core.JobParametersValidator which has only one method as shown below public interface JobParametersValidator { void validate(JobParameters parameters) throws JobParametersInvalidException; } Based on the signature of…… Continue reading Validating JobParameters using JobParametersValidator interface