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>
ItemStreamReader implementation that reads Json objects from a Resource
having the following format:
[
{
// JSON object
},
{
// JSON object
}
]
The implementation is not thread-safe.
- Since:
- 4.1
- Author:
- Mahmoud Ben Hassine
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newJsonItemReaderinstance.JsonItemReader(org.springframework.core.io.Resource resource, JsonObjectReader<T> jsonObjectReader) Create a newJsonItemReaderinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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, updateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, getName, setExecutionContextName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.batch.item.ItemReader
readMethods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
-
Constructor Details
-
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
-
JsonItemReader
public JsonItemReader()Create a newJsonItemReaderinstance.
-
-
Method Details
-
setJsonObjectReader
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
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:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doOpen
Description copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Specified by:
doOpenin classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doClose
Description copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Specified by:
doClosein classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-