Class JsonItemReader<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
- org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
- org.springframework.batch.item.json.JsonItemReader<T>
- Type Parameters:
T- the type of json objects to read
- All Implemented Interfaces:
ResourceAwareItemReaderItemStream<T>,ItemReader<T>,ItemStream,ItemStreamReader<T>
public class JsonItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements ResourceAwareItemReaderItemStream<T>
ItemStreamReaderimplementation that reads Json objects from aResourcehaving the following format:[ { // JSON object }, { // JSON object } ]The implementation is not thread-safe.
- Since:
- 4.1
- Author:
- Mahmoud Ben Hassine
Constructor Summary
Constructors Constructor Description JsonItemReader(org.springframework.core.io.Resource resource, JsonObjectReader<T> jsonObjectReader)Create a newJsonItemReaderinstance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoClose()Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().protected voiddoOpen()Open resources necessary to start reading input.protected TdoRead()Read next item from input.voidsetJsonObjectReader(JsonObjectReader<T> jsonObjectReader)Set theJsonObjectReaderto use to read and map Json fragments to domain objects.voidsetResource(org.springframework.core.io.Resource resource)voidsetStrict(boolean strict)In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)if the input resource does not exist.Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
Methods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.batch.item.ItemReader
read
Methods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
Constructor Detail
JsonItemReader
public JsonItemReader(org.springframework.core.io.Resource resource, JsonObjectReader<T> jsonObjectReader)Create a newJsonItemReaderinstance.- Parameters:
resource- the input json resourcejsonObjectReader- the json object reader to use
Method Detail
setJsonObjectReader
public void setJsonObjectReader(JsonObjectReader<T> jsonObjectReader)
Set theJsonObjectReaderto use to read and map Json fragments to domain objects.- Parameters:
jsonObjectReader- the json object reader to use
setStrict
public void setStrict(boolean strict)
In strict mode the reader will throw an exception onAbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)if the input resource does not exist.- Parameters:
strict- true by default
setResource
public void setResource(org.springframework.core.io.Resource resource)
- Specified by:
setResourcein interfaceResourceAwareItemReaderItemStream<T>
doRead
protected T doRead() throws java.lang.Exception
Description copied from class:AbstractItemCountingItemStreamItemReaderRead next item from input.- Specified by:
doReadin classAbstractItemCountingItemStreamItemReader<T>- Returns:
- an item or
nullif the data source is exhausted - Throws:
java.lang.Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
doOpen
protected void doOpen() throws java.lang.ExceptionDescription copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Specified by:
doOpenin classAbstractItemCountingItemStreamItemReader<T>- Throws:
java.lang.Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
doClose
protected void doClose() throws java.lang.ExceptionDescription copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Specified by:
doClosein classAbstractItemCountingItemStreamItemReader<T>- Throws:
java.lang.Exception- Allows subclasses to throw checked exceptions for interpretation by the framework