T
- the type of json objects to readpublic 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.
Constructor and Description |
---|
JsonItemReader(org.springframework.core.io.Resource resource,
JsonObjectReader<T> jsonObjectReader)
Create a new
JsonItemReader instance. |
Modifier and Type | Method and Description |
---|---|
protected void |
doClose()
Close the resources opened in
AbstractItemCountingItemStreamItemReader.doOpen() . |
protected void |
doOpen()
Open resources necessary to start reading input.
|
protected T |
doRead()
Read next item from input.
|
void |
setJsonObjectReader(JsonObjectReader<T> jsonObjectReader)
Set the
JsonObjectReader to use to read and map Json fragments to domain objects. |
void |
setResource(org.springframework.core.io.Resource resource) |
void |
setStrict(boolean strict)
In strict mode the reader will throw an exception on
AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext) if the
input resource does not exist. |
close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
getExecutionContextKey, setExecutionContextName, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, open, update
read
public JsonItemReader(org.springframework.core.io.Resource resource, JsonObjectReader<T> jsonObjectReader)
JsonItemReader
instance.resource
- the input json resourcejsonObjectReader
- the json object reader to usepublic void setJsonObjectReader(JsonObjectReader<T> jsonObjectReader)
JsonObjectReader
to use to read and map Json fragments to domain objects.jsonObjectReader
- the json object reader to usepublic void setStrict(boolean strict)
AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)
if the
input resource does not exist.strict
- true by defaultpublic void setResource(org.springframework.core.io.Resource resource)
setResource
in interface ResourceAwareItemReaderItemStream<T>
protected T doRead() throws java.lang.Exception
AbstractItemCountingItemStreamItemReader
doRead
in class AbstractItemCountingItemStreamItemReader<T>
null
if the data source is exhaustedjava.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected void doOpen() throws java.lang.Exception
AbstractItemCountingItemStreamItemReader
doOpen
in class AbstractItemCountingItemStreamItemReader<T>
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected void doClose() throws java.lang.Exception
AbstractItemCountingItemStreamItemReader
AbstractItemCountingItemStreamItemReader.doOpen()
.doClose
in class AbstractItemCountingItemStreamItemReader<T>
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework